Repository: edgedb/edgedb-python (language: python)

Issue:
Reject Nones in arrays on client side
edgedb-python will currently happily encode None in array arguments as NULL. 
https://github.com/edgedb/edgedb/pull/4511 prevents this on the server side, but probably we should reject it on the client side also?


Discussion / hints:

Fix patch:
diff --git a/edgedb/protocol/codecs/array.pyx b/edgedb/protocol/codecs/array.pyx
index 2f709531..34cc567b 100644
--- a/edgedb/protocol/codecs/array.pyx
+++ b/edgedb/protocol/codecs/array.pyx
@@ -60,7 +60,10 @@ cdef class BaseArrayCodec(BaseCodec):
         for i in range(objlen):
             item = obj[i]
             if item is None:
-                elem_data.write_int32(-1)
+                raise ValueError(
+                    "invalid array element at index {}: "
+                    "None is not allowed".format(i)
+                )
             else:
                 try:
                     self.sub_codec.encode(elem_data, item)


Test patch:
diff --git a/tests/test_async_query.py b/tests/test_async_query.py
index af334216..e51ac197 100644
--- a/tests/test_async_query.py
+++ b/tests/test_async_query.py
@@ -380,6 +380,12 @@ async def test_async_args_03(self):
                                     'combine positional and named parameters'):
             await self.client.query('select <int64>$0 + <int64>$bar;')
 
+        with self.assertRaisesRegex(edgedb.InvalidArgumentError,
+                                    "None is not allowed"):
+            await self.client.query(
+                "select <array<int64>>$0", [1, None, 3]
+            )
+
     async def test_async_args_04(self):
         aware_datetime = datetime.datetime.now(datetime.timezone.utc)
         naive_datetime = datetime.datetime.now()