]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- change to [ticket:2681], pre-coerce the array to list
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Apr 2013 21:08:02 +0000 (17:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Apr 2013 21:08:02 +0000 (17:08 -0400)
unconditonally instead so that it works in all cases.

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/test_postgresql.py

index b64a188f79cb6f840fa076a1a888d73e873494fe..489cad5824a195c3ce0692928c0f2bac59be5d95 100644 (file)
       :tickets: 2681
 
       The operators for the Postgresql ARRAY type supports
-      input types of sets, generators, etc. but only when a dimension
-      is specified for the ARRAY; otherwise, the dialect
-      needs to peek inside of "arr[0]" to guess how many
-      dimensions are in use.  If this occurs with a non
-      list/tuple type, the error message is now informative
-      and directs to specify a dimension for the ARRAY.
+      input types of sets, generators, etc. even when
+      a dimension is not specified, by turning the given
+      iterable into a collection unconditionally.
 
     .. change::
       :tags: bug, mysql
index f3a88ff70970a84e2182a1c8edf9852cbea478aa..82660d96c7aab459a1d6d5778c6f0c4e06553a80 100644 (file)
@@ -669,23 +669,13 @@ class ARRAY(sqltypes.Concatenable, sqltypes.TypeEngine):
     def compare_values(self, x, y):
         return x == y
 
-    def _test_array_of_scalars(self, arr):
-        if not arr:
-            return True
-        else:
-            try:
-                return not isinstance(arr[0], (list, tuple))
-            except TypeError:
-                raise TypeError(
-                            "Cannot auto-coerce ARRAY value of type "
-                            "%s unless dimensions are specified "
-                            "for ARRAY type" % type(arr))
-
     def _proc_array(self, arr, itemproc, dim, collection):
-        if dim == 1 or (
-                    dim is None and
-                    self._test_array_of_scalars(arr)
-                ):
+        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__'):
             if itemproc:
                 return collection(itemproc(x) for x in arr)
             else:
index 3455b8ff1028c20fd1dfb6d53639dbae4b9cf696..42c8c85c4758b38c725eee75a59953f99e3ce3b2 100644 (file)
@@ -2279,21 +2279,14 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults):
         )
 
     def test_undim_array_contains_set_exec(self):
-        assert_raises_message(
-            exc.StatementError,
-            "Cannot auto-coerce ARRAY value of type",
-            self._test_undim_array_contains_typed_exec, set
-        )
+        self._test_undim_array_contains_typed_exec(set)
 
     def test_undim_array_contains_list_exec(self):
         self._test_undim_array_contains_typed_exec(list)
 
     def test_undim_array_contains_generator_exec(self):
-        assert_raises_message(
-            exc.StatementError,
-            "Cannot auto-coerce ARRAY value of type",
-            self._test_undim_array_contains_typed_exec, lambda elem: (x for x in elem)
-        )
+        self._test_undim_array_contains_typed_exec(
+                    lambda elem: (x for x in elem))
 
     def _test_dim_array_contains_typed_exec(self, struct):
         dim_arrtable = self.tables.dim_arrtable