fix: avoid failed assert passing more arguments than placeholders

Fix #1791
This commit is contained in:
Daniele Varrazzo 2025-10-10 01:10:32 +02:00
parent 8308c19d6a
commit 4fde6560c3
3 changed files with 8 additions and 1 deletions

2
NEWS
View File

@ -5,6 +5,8 @@ What's new in psycopg 2.9.11
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Add support for Python 3.14.
- Avoid a segfault passing more arguments than placeholders if Python is built
with assertions enabled (:ticket:`#1791`).
- `~psycopg2.errorcodes` map and `~psycopg2.errors` classes updated to
PostgreSQL 18.
- Drop support for Python 3.8.

View File

@ -342,7 +342,7 @@ _psyco_curs_merge_query_args(cursorObject *self,
if (PyObject_HasAttrString(arg, "args")) {
PyObject *args = PyObject_GetAttrString(arg, "args");
PyObject *str = PySequence_GetItem(args, 0);
const char *s = Bytes_AS_STRING(str);
const char *s = PyUnicode_AsUTF8(str);
Dprintf("curs_execute: -> %s", s);

View File

@ -139,6 +139,11 @@ class CursorTests(ConnectingTestCase):
self.assertRaises(psycopg2.ProgrammingError,
cur.mogrify, "select %(foo, %(bar)", {'foo': 1, 'bar': 2})
def test_bad_params_number(self):
cur = self.conn.cursor()
self.assertRaises(IndexError, cur.execute, "select %s, %s", [1])
self.assertRaises(TypeError, cur.execute, "select %s", [1, 2])
def test_cast(self):
curs = self.conn.cursor()