Skip to content

schema_translate_map does not work for Postgresql native enum within the CREATE TABLE #5158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zzzeek opened this issue Feb 17, 2020 · 3 comments
Labels
bug Something isn't working datatypes things to do with database types, like VARCHAR and others postgresql schema things related to the DDL related objects like Table, Column, CreateIndex, etc.
Milestone

Comments

@zzzeek
Copy link
Member

zzzeek commented Feb 17, 2020

While CREATE TYPE takes advantage of schema_translate_map, the use of the enum in the table does not:

from sqlalchemy import create_engine
from sqlalchemy import *

metadata = MetaData()

t = Table(
    "table1",
    metadata,
    Column("id", Integer(), nullable=False),
    Column("type1", Enum("One", "Two", name="enum1", schema="X"), nullable=True),
    PrimaryKeyConstraint("id"),
    schema="X"
)


e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)

with e.connect() as conn:
    trans = conn.begin()
    conn = conn.execution_options(schema_translate_map={"X": "test_schema"})
    t.create(conn)


    trans.rollback()

output, enum is created correctly but not referenced in the table correctly:

CREATE TYPE test_schema.enum1 AS ENUM ('One', 'Two')
2020-02-17 15:02:27,535 INFO sqlalchemy.engine.base.Engine {}
2020-02-17 15:02:27,536 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE test_schema.table1 (
	id SERIAL NOT NULL, 
	type1 "X".enum1, 
	PRIMARY KEY (id)
)

@zzzeek zzzeek added datatypes things to do with database types, like VARCHAR and others postgresql schema things related to the DDL related objects like Table, Column, CreateIndex, etc. bug Something isn't working labels Feb 17, 2020
@zzzeek zzzeek added this to the 1.3.x milestone Feb 17, 2020
@zzzeek
Copy link
Member Author

zzzeek commented Feb 17, 2020

same issue if the translate source is "None".

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

Pass DDLCompiler IdentifierPreparer to visit_ENUM https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1726

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the rel_1_3 branch:

Pass DDLCompiler IdentifierPreparer to visit_ENUM https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1727

sqlalchemy-bot pushed a commit that referenced this issue Feb 17, 2020
Fixed issue where the "schema_translate_map" feature would not work with a
PostgreSQL native enumeration type (i.e. :class:`.Enum`,
:class:`.postgresql.ENUM`) in that while the "CREATE TYPE" statement would
be emitted with the correct schema, the schema would not be rendered in
the CREATE TABLE statement at the point at which the enumeration was
referenced.

Fixes: #5158
Change-Id: I41529785de2e736c70a142c2ae5705060bfed73e
(cherry picked from commit 89b8c34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datatypes things to do with database types, like VARCHAR and others postgresql schema things related to the DDL related objects like Table, Column, CreateIndex, etc.
Projects
None yet
Development

No branches or pull requests

2 participants