return "%s.%r" % (dname, type_)
elif impl_rt:
return impl_rt
+ elif not _skip_variants and sqla_compat._type_has_variants(type_):
+ return _render_Variant_type(type_, autogen_context)
elif mod.startswith("sqlalchemy."):
- if not _skip_variants and sqla_compat._type_has_variants(type_):
- return _render_Variant_type(type_, autogen_context)
if "_render_%s_type" % type_.__visit_name__ in globals():
fn = globals()["_render_%s_type" % type_.__visit_name__]
return fn(type_, autogen_context)
--- /dev/null
+.. change::
+ :tags: bug, autogenerate
+ :tickets: 1167
+
+ Fixed issue where rendering of user-defined types that then went onto use
+ the ``.with_variant()`` method would fail to render, if using SQLAlchemy
+ 2.0's version of variants.
+
" # ### end Alembic commands ###",
)
- def test_repr_custom_type_w_sqla_prefix(self):
+ @testing.combinations("sqlaname", "nonsqlaname", argnames="modname")
+ @testing.combinations("usevariant", "plain", argnames="construct")
+ def test_repr_custom_type(self, modname, construct):
+ """test #1167 as well as other user defined type variations"""
+
self.autogen_context.opts["user_module_prefix"] = None
class MyType(UserDefinedType):
pass
- MyType.__module__ = "sqlalchemy_util.types"
+ if modname == "sqlaname":
+ MyType.__module__ = mod = "sqlalchemy_util.types"
+ elif modname == "nonsqlaname":
+ MyType.__module__ = mod = "mymodule"
+ else:
+ assert False
- type_ = MyType()
+ if construct == "usevariant":
+ type_ = MyType().with_variant(String(), "mysql")
+ elif construct == "plain":
+ type_ = MyType()
+ else:
+ assert False
eq_ignore_whitespace(
autogenerate.render._repr_type(type_, self.autogen_context),
- "sqlalchemy_util.types.MyType()",
+ f"{mod}.MyType()"
+ + (
+ ".with_variant(sa.String(), 'mysql')"
+ if construct == "usevariant"
+ else ""
+ ),
)
def test_render_variant(self):