Skip to content

Commit

Permalink
render type.impl when type is a TypeDecorator instance
Browse files Browse the repository at this point in the history
  • Loading branch information
saifelse committed Jan 5, 2024
1 parent abc8002 commit 60655db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions alembic/autogenerate/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ def _repr_type(
if rendered is not False:
return rendered

if isinstance(type_, sqltypes.TypeDecorator):
type_ = type_.impl

if hasattr(autogen_context.migration_context, "impl"):
impl_rt = autogen_context.migration_context.impl.render_type(
type_, autogen_context
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

0 comments on commit 60655db

Please sign in to comment.