]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
restore empty list logic to ARRAY of ENUM parsing
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 20:01:47 +0000 (15:01 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 20:04:55 +0000 (15:04 -0500)
Fixed regression where the change in :ticket:`7148` to repair ENUM handling
in PostgreSQL broke the use case of an empty ARRAY of ENUM, preventing rows
that contained an empty array from being handled correctly when fetching
results.

Fixes: #7590
Change-Id: I43a35ef25281a6e0a26b698efebef6ba12a63e8c
(cherry picked from commit dda5c43cab88daad02bc871cf40bf4984e94a031)

doc/build/changelog/unreleased_14/7590.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/array.py
test/dialect/postgresql/test_types.py

diff --git a/doc/build/changelog/unreleased_14/7590.rst b/doc/build/changelog/unreleased_14/7590.rst
new file mode 100644 (file)
index 0000000..822adf6
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, postgresql, regression
+    :tickets: 7590
+
+    Fixed regression where the change in :ticket:`7148` to repair ENUM handling
+    in PostgreSQL broke the use case of an empty ARRAY of ENUM, preventing rows
+    that contained an empty array from being handled correctly when fetching
+    results.
index 568e5b7b06504b275954f2ae6296b66db6a93aae..daf7c5d40d09e54907fd535d4a685b430cf17977 100644 (file)
@@ -389,9 +389,10 @@ class ARRAY(sqltypes.ARRAY):
 
 
 def _split_enum_values(array_string):
+
     if '"' not in array_string:
         # no escape char is present so it can just split on the comma
-        return array_string.split(",")
+        return array_string.split(",") if array_string else []
 
     # handles quoted strings from:
     # r'abc,"quoted","also\\\\quoted", "quoted, comma", "esc \" quot", qpr'
index e5b9d48676c593ca88672d16de73e1641806392a..8ec345d170ab2cb5273d24106fb408645459e531 100644 (file)
@@ -1908,7 +1908,7 @@ class ArrayRoundTripTest(object):
         t.drop(connection)
         eq_(inspect(connection).get_enums(), [])
 
-    def _type_combinations(exclude_json=False):
+    def _type_combinations(exclude_json=False, exclude_empty_lists=False):
         def str_values(x):
             return ["one", "two: %s" % x, "three", "four", "five"]
 
@@ -1942,6 +1942,9 @@ class ArrayRoundTripTest(object):
                 AnEnum.Foo,
             ]
 
+        def empty_list(x):
+            return []
+
         class inet_str(str):
             def __eq__(self, other):
                 return str(self) == str(other)
@@ -2075,6 +2078,15 @@ class ArrayRoundTripTest(object):
             ),
         ]
 
+        if not exclude_empty_lists:
+            elements.extend(
+                [
+                    (postgresql.ENUM(AnEnum), empty_list),
+                    (sqltypes.Enum(AnEnum, native_enum=True), empty_list),
+                    (sqltypes.Enum(AnEnum, native_enum=False), empty_list),
+                    (postgresql.ENUM(AnEnum, native_enum=True), empty_list),
+                ]
+            )
         if not exclude_json:
             elements.extend(
                 [
@@ -2163,7 +2175,7 @@ class ArrayRoundTripTest(object):
             connection.scalar(select(table.c.bar).where(table.c.id == 2)),
         )
 
-    @_type_combinations()
+    @_type_combinations(exclude_empty_lists=True)
     def test_type_specific_slice_update(
         self, type_specific_fixture, connection, type_, gen
     ):
@@ -2190,7 +2202,7 @@ class ArrayRoundTripTest(object):
 
         eq_(rows, [(gen(1),), (sliced_gen,)])
 
-    @_type_combinations(exclude_json=True)
+    @_type_combinations(exclude_json=True, exclude_empty_lists=True)
     def test_type_specific_value_delete(
         self, type_specific_fixture, connection, type_, gen
     ):