diff options
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 22 | ||||
-rw-r--r-- | test/dialect/test_postgresql.py | 13 |
3 files changed, 12 insertions, 32 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index b64a188f7..489cad582 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,12 +11,9 @@ :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 diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index f3a88ff70..82660d96c 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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: diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 3455b8ff1..42c8c85c4 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -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 |