]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
tweak this some more to handle the array being empty again
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Apr 2013 21:24:31 +0000 (17:24 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Apr 2013 21:24:31 +0000 (17:24 -0400)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/test_postgresql.py

index 82660d96c7aab459a1d6d5778c6f0c4e06553a80..5d9368893a36b807dd53d4749d8791f1e2355eda 100644 (file)
@@ -671,11 +671,9 @@ class ARRAY(sqltypes.Concatenable, sqltypes.TypeEngine):
 
     def _proc_array(self, arr, itemproc, dim, collection):
         if dim is None:
-            if arr is None:
-                arr = []
-            else:
-                arr = list(arr)
-        if dim == 1 or dim is None and not hasattr(arr[0], '__iter__'):
+            arr = list(arr)
+        if dim == 1 or dim is None and (
+                        not arr or not hasattr(arr[0], '__iter__')):
             if itemproc:
                 return collection(itemproc(x) for x in arr)
             else:
index 42c8c85c4758b38c725eee75a59953f99e3ce3b2..e217eb0b812b20832c96b15e126e9c1d580f7bc3 100644 (file)
@@ -2247,6 +2247,17 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults):
             7
         )
 
+    def test_undim_array_empty(self):
+        arrtable = self.tables.arrtable
+        self._fixture_456(arrtable)
+        eq_(
+            testing.db.scalar(
+                select([arrtable.c.intarr]).
+                    where(arrtable.c.intarr.contains([]))
+            ),
+            [4, 5, 6]
+        )
+
     def test_array_getitem_slice_exec(self):
         arrtable = self.tables.arrtable
         testing.db.execute(