Skip to content
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

render type.impl when type is a TypeDecorator instance #1387

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alembic/autogenerate/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ def _repr_type(
else:
prefix = _sqlalchemy_autogenerate_prefix(autogen_context)
return "%s%r" % (prefix, type_)
elif isinstance(type_, sqltypes.TypeDecorator):
return _repr_type(cast("TypeEngine", type_.impl), autogen_context, _skip_variants)
else:
prefix = _user_autogenerate_prefix(autogen_context, type_)
return "%s%r" % (prefix, type_)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_autogen_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from sqlalchemy.sql import literal_column
from sqlalchemy.sql import table
from sqlalchemy.types import TIMESTAMP
from sqlalchemy.types import TypeDecorator
from sqlalchemy.types import UserDefinedType

from alembic import autogenerate
Expand Down Expand Up @@ -1078,6 +1079,21 @@ def test_render_add_column(self):
"server_default='5', nullable=True))",
)

def test_render_add_column_type_decorator(self):
self.autogen_context.opts["user_module_prefix"] = None

class MyType(TypeDecorator):
impl = Integer

op_obj = ops.AddColumnOp(
"foo", Column("x", MyType, server_default="5")
)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.add_column('foo', sa.Column('x', sa.Integer(), "
"server_default='5', nullable=True))",
)

@testing.emits_warning("Can't validate argument ")
def test_render_add_column_custom_kwarg(self):
col = Column(
Expand Down