]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Don't return None as text in Python 9.6
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 13 Jan 2021 00:02:13 +0000 (01:02 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 13 Jan 2021 00:02:13 +0000 (01:02 +0100)
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

psycopg3/psycopg3/_transform.py
psycopg3_c/psycopg3_c/_psycopg3/transform.pyx
tests/test_adapt.py

index a593b2c406a3cbc725caa0530e491e45f9c16e98..ccc8c1675f0fed8d10daac28e0976897ec6830b1 100644 (file)
@@ -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:
index ce62c7ddf9edf78d272451d62ef536dfe1a139fe..f8c17eb3033fd356e8236c845338b86cde2498b4 100644 (file)
@@ -257,7 +257,7 @@ cdef class Transformer:
                         <PyObject *>param, NULL)
             else:
                 dumped = None
-                oid = self._unknown_oid
+                oid = oids.INVALID_OID
 
             Py_INCREF(dumped)
             PyList_SET_ITEM(ps, i, dumped)
index 1f4287f5da815b91c9dfae91adf64d05b9e1b9d0..5b7cfc77505386a5cf4b07f6346b1b378e373e43 100644 (file)
@@ -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]