diff options
-rw-r--r-- | doc/build/changelog/unreleased_14/7720_7789.rst | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/enumerated.py | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 5 | ||||
-rw-r--r-- | test/dialect/mysql/test_types.py | 18 | ||||
-rw-r--r-- | test/sql/test_types.py | 7 |
5 files changed, 47 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_14/7720_7789.rst b/doc/build/changelog/unreleased_14/7720_7789.rst new file mode 100644 index 000000000..5c1026ef5 --- /dev/null +++ b/doc/build/changelog/unreleased_14/7720_7789.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, sql, mysql + :tickets: 7720, 7789 + + Fixed issues in :class:`_mysql.SET` datatype as well as :class:`.Enum` + where the ``__repr__()`` method would not render all optional parameters in + the string output, impacting the use of these types in Alembic + autogenerate. Pull request for MySQL courtesy Yuki Nishimine. + diff --git a/lib/sqlalchemy/dialects/mysql/enumerated.py b/lib/sqlalchemy/dialects/mysql/enumerated.py index 875858871..c35b7226d 100644 --- a/lib/sqlalchemy/dialects/mysql/enumerated.py +++ b/lib/sqlalchemy/dialects/mysql/enumerated.py @@ -233,3 +233,12 @@ class SET(_StringType): def adapt(self, impltype, **kw): kw["retrieve_as_bitwise"] = self.retrieve_as_bitwise return util.constructor_copy(self, impltype, *self.values, **kw) + + def __repr__(self): + return util.generic_repr( + self, + to_inspect=[SET, _StringType], + additional_kw=[ + ("retrieve_as_bitwise", False), + ], + ) diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index d022a24ca..3794fd8f7 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1453,7 +1453,10 @@ class Enum(Emulated, String, TypeEngine[Union[str, enum.Enum]], SchemaType): def __repr__(self): return util.generic_repr( self, - additional_kw=[("native_enum", True)], + additional_kw=[ + ("native_enum", True), + ("create_constraint", False), + ], to_inspect=[Enum, SchemaType], ) diff --git a/test/dialect/mysql/test_types.py b/test/dialect/mysql/test_types.py index 3d26e1d07..de93a97a4 100644 --- a/test/dialect/mysql/test_types.py +++ b/test/dialect/mysql/test_types.py @@ -1310,6 +1310,24 @@ class EnumSetTest( [("", ""), ("", ""), ("two", "two"), (None, None)], ) + @testing.combinations( + ( + [""], + {"retrieve_as_bitwise": True}, + "SET('', retrieve_as_bitwise=True)", + ), + (["a"], {}, "SET('a')"), + (["a", "b", "c"], {}, "SET('a', 'b', 'c')"), + ( + ["a", "b", "c"], + {"collation": "utf8_bin"}, + "SET('a', 'b', 'c', collation='utf8_bin')", + ), + argnames="value,kw,expected", + ) + def test_set_repr(self, value, kw, expected): + eq_(repr(mysql.SET(*value, **kw)), expected) + def colspec(c): return testing.db.dialect.ddl_compiler( diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 4e1048cb6..58dfa4dd8 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -2479,6 +2479,13 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): "inherit_schema=True, native_enum=False)", ) + def test_repr_two(self): + e = Enum("x", "y", name="somename", create_constraint=True) + eq_( + repr(e), + "Enum('x', 'y', name='somename', create_constraint=True)", + ) + def test_length_native(self): e = Enum("x", "y", "long", length=42) |