unconditonally instead so that it works in all cases.
: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
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:
)
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