]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix reflection of enum named intervalsomething
authorFederico Caselli <cfederico87@gmail.com>
Mon, 21 Jul 2025 21:36:43 +0000 (23:36 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 28 Jul 2025 16:40:25 +0000 (18:40 +0200)
Fixes bug that would mistakenly interpret a domain or enum type
with name starting in ``interval`` as an ``INTERVAL`` type while
reflecting a table.

Fixes: #12744
Change-Id: I89ab287c3847ca545691afe73f26d86bf2337ae0

doc/build/changelog/unreleased_20/12744.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_reflection.py

diff --git a/doc/build/changelog/unreleased_20/12744.rst b/doc/build/changelog/unreleased_20/12744.rst
new file mode 100644 (file)
index 0000000..0adbdc7
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, reflection, postgresql
+    :tickets: 12744
+
+    Fixes bug that would mistakenly interpret a domain or enum type
+    with name starting in ``interval`` as an ``INTERVAL`` type while
+    reflecting a table.
index 43251ce2773aeaf49d34582fa4150d55dbf9d3ab..d06b131a62501d7c48e4059689005f0886071108 100644 (file)
@@ -3941,7 +3941,8 @@ class PGDialect(default.DefaultDialect):
                 charlen = int(attype_args[0])
                 args = (charlen,)
 
-        elif attype.startswith("interval"):
+        # a domain or enum can start with interval, so be mindful of that.
+        elif attype == "interval" or attype.startswith("interval "):
             schema_type = INTERVAL
 
             field_match = re.match(r"interval (.+)", attype)
index 5dd8e00070d6a2397ae6766176816ccda33323ee..7061b6e0fc6608de6735f2bb3726c0cee295ff2d 100644 (file)
@@ -2237,6 +2237,17 @@ class ReflectionTest(
         t = Table("t", MetaData(), autoload_with=connection)
         eq_(t.c.x.type.enums, [])
 
+    def test_enum_starts_with_interval(self, metadata, connection):
+        """Test for #12744"""
+        enum_type = postgresql.ENUM("day", "week", name="intervalunit")
+        t1 = Table("t1", metadata, Column("col", enum_type))
+        t1.create(connection)
+
+        insp = inspect(connection)
+        cols = insp.get_columns("t1")
+        is_true(isinstance(cols[0]["type"], postgresql.ENUM))
+        eq_(cols[0]["type"].enums, ["day", "week"])
+
     def test_reflection_with_unique_constraint(self, metadata, connection):
         insp = inspect(connection)