From: Daniele Varrazzo Date: Wed, 13 Jan 2021 00:02:13 +0000 (+0100) Subject: Don't return None as text in Python 9.6 X-Git-Tag: 3.0.dev0~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91544696d24c6ee75376dd572257be9dc9ce7c0f;p=thirdparty%2Fpsycopg.git Don't return None as text in Python 9.6 This makes to require a cast on pretty much any placeholder that might receive a None, which is really asking too much. Exploratory commit to test what can be done with PG 9.6. The result shows that in PG 9.6 it's pretty much impossible to use prepared statements: neither for executemany nor for preparation. Tests failing: - tests/test_cursor.py::test_executemany_null_first - tests/test_cursor_async.py::test_executemany_null_first - tests/test_prepared.py::test_different_types - tests/test_prepared_async.py::test_different_types all with: psycopg3.errors.IndeterminateDatatype: could not determine data type of parameter $x --- diff --git a/psycopg3/psycopg3/_transform.py b/psycopg3/psycopg3/_transform.py index a593b2c40..ccc8c1675 100644 --- a/psycopg3/psycopg3/_transform.py +++ b/psycopg3/psycopg3/_transform.py @@ -111,7 +111,7 @@ class Transformer(AdaptContext): self, params: Sequence[Any], formats: Sequence[Format] ) -> Tuple[List[Any], Tuple[int, ...]]: ps: List[Optional[bytes]] = [None] * len(params) - ts = [self._unknown_oid] * len(params) + ts = [INVALID_OID] * len(params) dumpers = self._row_dumpers if not dumpers: diff --git a/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx b/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx index ce62c7ddf..f8c17eb30 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx +++ b/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx @@ -257,7 +257,7 @@ cdef class Transformer: param, NULL) else: dumped = None - oid = self._unknown_oid + oid = oids.INVALID_OID Py_INCREF(dumped) PyList_SET_ITEM(ps, i, dumped) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 1f4287f5d..5b7cfc775 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -196,10 +196,8 @@ def test_array_dumper(conn, fmt_out): def test_none_type_argument(conn, fmt_in): cur = conn.cursor() cur.execute("create table none_args (id serial primary key, num integer)") - cast = "" if conn.pgconn.server_version >= 100000 else "::int" cur.execute( - f"insert into none_args (num) values (%s{cast}) returning id", - (None,), + "insert into none_args (num) values (%s) returning id", (None,) ) assert cur.fetchone()[0]