mod = type(type_).__module__
imports = autogen_context.imports
- if mod.startswith("sqlalchemy.dialects"):
+
+ if not _skip_variants and sqla_compat._type_has_variants(type_):
+ return _render_Variant_type(type_, autogen_context)
+ elif mod.startswith("sqlalchemy.dialects"):
match = re.match(r"sqlalchemy\.dialects\.(\w+)", mod)
assert match is not None
dname = match.group(1)
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 "_render_%s_type" % type_.__visit_name__ in globals():
fn = globals()["_render_%s_type" % type_.__visit_name__]
--- /dev/null
+.. change::
+ :tags: bug, autogenerate
+ :tickets: 1585
+
+ Fixed bug where autogen render of a "variant" type would fail to catch the
+ variants if the leading type were a dialect-specific type, rather than a
+ generic type.
+
from sqlalchemy import Unicode
from sqlalchemy import UniqueConstraint
from sqlalchemy import VARCHAR
+from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy.engine.default import DefaultDialect
from sqlalchemy.sql import and_
from sqlalchemy.sql import column
.with_variant(CHAR(15), "oracle")
)
- # the new Black formatting will help a lot with this
eq_ignore_whitespace(
autogenerate.render._repr_type(type_, self.autogen_context),
"sa.String(length=5)."
"with_variant(sa.CHAR(length=15), 'oracle')",
)
+ def test_render_reverse_variant(self):
+ """test #1585"""
+
+ self.autogen_context.opts["user_module_prefix"] = None
+
+ type_ = LONGTEXT().with_variant(String(10), "oracle")
+
+ eq_ignore_whitespace(
+ autogenerate.render._repr_type(type_, self.autogen_context),
+ "mysql.LONGTEXT()." "with_variant(sa.String(length=10), 'oracle')",
+ )
+
def test_repr_user_type_user_prefix_None(self):
class MyType(UserDefinedType):
def get_col_spec(self):