Skip to content

Render the PostgreSQL DOMAIN type in autogenerate#1831

Open
cycsmail wants to merge 1 commit into
sqlalchemy:mainfrom
cycsmail:domain-render-1360
Open

Render the PostgreSQL DOMAIN type in autogenerate#1831
cycsmail wants to merge 1 commit into
sqlalchemy:mainfrom
cycsmail:domain-render-1360

Conversation

@cycsmail

Copy link
Copy Markdown

Fixes: #1360

Autogenerate had no renderer for the PostgreSQL DOMAIN type, so _repr_type() fell back to plain repr(). That dropped every constructor argument except name/data_type and left the underlying type unqualified (e.g. DOMAIN('email', CITEXT(), check="...") rendered as postgresql.DOMAIN('email', CITEXT())), silently losing the check constraint.

Adds _render_DOMAIN_type to PostgresqlImpl (which render_type already dispatches to via _render_<visit_name>_type). It renders the name, the underlying data_type through render._repr_type for the right prefix/import, and each of collation, default, constraint_name, not_null, check, create_type only when it differs from its default. The issue's column now renders as:

sa.Column('email', postgresql.DOMAIN('email', postgresql.CITEXT(),
    check="value ~ '^my_.*$'"), nullable=False)

Tests are guarded by config.requirements.sqlalchemy_2 since DOMAIN only exists on SQLAlchemy 2.0+. With the source change stashed both new tests fail (missing prefix and kwargs); with the fix they pass. pytest -q -k domain → 2 passed, and tests/test_postgresql.py tests/test_autogen_render.py → 249 passed, 2 skipped. Lint clean on the changed files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering postgresql dialect DOMAIN field

1 participant