Skip to content

Commit d8e0e00

Browse files
gh-118928: sqlite3: disallow sequences of params with named placeholders (#118929)
Follow-up of gh-101693. The previous DeprecationWarning is replaced with raising sqlite3.ProgrammingError. Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 7a97ee5 commit d8e0e00

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ sqlite3
142142
* Remove :data:`!version` and :data:`!version_info` from :mod:`sqlite3`.
143143
(Contributed by Hugo van Kemenade in :gh:`118924`.)
144144

145+
* Disallow using a sequence of parameters with named placeholders.
146+
This had previously raised a :exc:`DeprecationWarning` since Python 3.12;
147+
it will now raise a :exc:`sqlite3.ProgrammingError`.
148+
(Contributed by Erlend E. Aasland in :gh:`118928` and :gh:`101693`.)
149+
145150
typing
146151
------
147152

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,8 @@ def test_execute_named_param_and_sequence(self):
878878
msg = "Binding.*is a named parameter"
879879
for query, params in dataset:
880880
with self.subTest(query=query, params=params):
881-
with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
881+
with self.assertRaisesRegex(sqlite.ProgrammingError, msg) as cm:
882882
self.cu.execute(query, params)
883-
self.assertEqual(cm.filename, __file__)
884883

885884
def test_execute_indexed_nameless_params(self):
886885
# See gh-117995: "'?1' is considered a named placeholder"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Disallow using a sequence of parameters with named placeholders in
2+
:mod:`sqlite3` queries. Patch by Erlend E. Aasland.

Modules/_sqlite/cursor.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,11 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
670670
for (i = 0; i < num_params; i++) {
671671
const char *name = sqlite3_bind_parameter_name(self->st, i+1);
672672
if (name != NULL && name[0] != '?') {
673-
int ret = PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
673+
PyErr_Format(state->ProgrammingError,
674674
"Binding %d ('%s') is a named parameter, but you "
675675
"supplied a sequence which requires nameless (qmark) "
676-
"placeholders. Starting with Python 3.14 an "
677-
"sqlite3.ProgrammingError will be raised.",
676+
"placeholders.",
678677
i+1, name);
679-
if (ret < 0) {
680-
return;
681-
}
682678
}
683679

684680
if (PyTuple_CheckExact(parameters)) {

0 commit comments

Comments
 (0)