]> 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:31 +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

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 abe17ea35e2ef003d9abe3dddc516281fb05c56d..74643c4d92120dac604067e4ab0214938a3d3be8 100644 (file)
@@ -385,9 +385,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 991b0ed9d4a01a2723de3a7cd67a913e41b9c803..0c00c76333c1164c9c3eb55293efb737433b969e 100644 (file)
@@ -1911,7 +1911,7 @@ class ArrayRoundTripTest:
         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"]
 
@@ -1945,6 +1945,9 @@ class ArrayRoundTripTest:
                 AnEnum.Foo,
             ]
 
+        def empty_list(x):
+            return []
+
         class inet_str(str):
             def __eq__(self, other):
                 return str(self) == str(other)
@@ -2078,6 +2081,15 @@ class ArrayRoundTripTest:
             ),
         ]
 
+        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(
                 [
@@ -2166,7 +2178,7 @@ class ArrayRoundTripTest:
             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
     ):
@@ -2193,7 +2205,7 @@ class ArrayRoundTripTest:
 
         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
     ):