]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
raise for ENUM/DOMAIN with reserved type name and no schema
authorKapilDagur <kapildagur1306@gmail.com>
Sat, 13 Sep 2025 18:37:31 +0000 (14:37 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 20 Sep 2025 15:29:26 +0000 (11:29 -0400)
commit555a18ac02b167db8aaace4c82f8f1076af166b5
treed453b55b0ad5fb990661117e464125b7489ec6ac
parent13f569fd615485c50e07f211e37e45d749ccc40d
raise for ENUM/DOMAIN with reserved type name and no schema

A :class:`.CompileError` is raised if attempting to create a PostgreSQL
:class:`_postgresql.ENUM` or :class:`_postgresql.DOMAIN` datatype using a
name that matches a known pg_catalog datatype name, and a default schema is
not specified.   These types must be explicit within a schema in order to
be differentiated from the built-in pg_catalog type.  The "public" or
otherwise default schema is not chosen by default here since the type can
only be reflected back using the explicit schema name as well (it is
otherwise not visible due to the pg_catalog name).  Pull request courtesy
Kapil Dagur.

We originally thought we were going to do some default logic for the
default / "public" schema however this produces a type that is not
symmetric to its reflection, since the schema name must be explicit
for our current reflection queries.

So since it's an extremely bad idea to make an ENUM/DOMAIN with a
reserved type name anyway, we raise a compileerror if the type
has a known name.   this is not robust against other names that
might exist in pg_catalog or other schemas that are in the search
path with these names.  People just have to know what they're doing
here, the error here only covers a small subset of real world cases.

Fixes: #12761
Closes: #12822
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12822
Pull-request-sha: 793cf27be28a37e8882d89ba6b79570c79f936ac

Change-Id: I9df9c216ab4102f06685a64ae7e55db1b3a9535e
doc/build/changelog/unreleased_21/12761.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_types.py