Skip to content

Commit 99b73c0

Browse files
Fixed MySQL DOUBLE column type rendering (#371)
* Fixed MySQL DOUBLE column type rendering Fixes #335. * A cleaner approach to type adaptation variations * Removed PostgreSQL float hacks --------- Co-authored-by: sheinbergon <[email protected]>
1 parent 6da9a0b commit 99b73c0

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version history
1111
- Fixed ``AttributeError`` when metadata contains user defined column types
1212
- Fixed ``AssertionError`` when metadata contains a column type that is a type decorator
1313
with an all-uppercase name
14+
- Fixed MySQL ``DOUBLE`` column types being rendered with the wrong arguments
1415

1516
**3.0.0rc5**
1617

src/sqlacodegen/generators.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
Constraint,
2727
DefaultClause,
2828
Enum,
29-
Float,
3029
ForeignKey,
3130
ForeignKeyConstraint,
3231
Identity,
@@ -712,14 +711,7 @@ def get_adapted_type(self, coltype: Any) -> Any:
712711
# If the adapted column type does not render the same as the
713712
# original, don't substitute it
714713
if new_coltype.compile(self.bind.engine.dialect) != compiled_type:
715-
# Make an exception to the rule for Float and arrays of Float,
716-
# since at least on PostgreSQL, Float can accurately represent
717-
# both REAL and DOUBLE_PRECISION
718-
if not isinstance(new_coltype, Float) and not (
719-
isinstance(new_coltype, ARRAY)
720-
and isinstance(new_coltype.item_type, Float)
721-
):
722-
break
714+
break
723715
except CompileError:
724716
# If the adapted column type can't be compiled, don't substitute it
725717
break

tests/test_generator_tables.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ def test_mysql_column_types(generator: CodeGenerator) -> None:
238238
generator.metadata,
239239
Column("id", mysql.INTEGER),
240240
Column("name", mysql.VARCHAR(255)),
241+
Column("double", mysql.DOUBLE(1, 2)),
241242
Column("set", mysql.SET("one", "two")),
242243
)
243244

244245
validate_code(
245246
generator.generate(),
246247
"""\
247248
from sqlalchemy import Column, Integer, MetaData, String, Table
248-
from sqlalchemy.dialects.mysql import SET
249+
from sqlalchemy.dialects.mysql import DOUBLE, SET
249250
250251
metadata = MetaData()
251252
@@ -254,6 +255,7 @@ def test_mysql_column_types(generator: CodeGenerator) -> None:
254255
'simple_items', metadata,
255256
Column('id', Integer),
256257
Column('name', String(255)),
258+
Column('double', DOUBLE(1, 2)),
257259
Column('set', SET('one', 'two'))
258260
)
259261
""",

0 commit comments

Comments
 (0)