Skip to content

Commit 8ab2d49

Browse files
committed
Fixed _IntegerType, _StringType etc. being rendered on MySQL
1 parent d906e0f commit 8ab2d49

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Version history
66

77
* Fixed TypeError when inflect could not determine the singular name of a table for a many-to-1 relationship
88

9+
* Fixed _IntegerType, _StringType etc. being rendered instead of proper types on MySQL
10+
911

1012
1.1.0
1113
-----

sqlacodegen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = '1.1.1.pre1'
1+
version = '1.1.1'

sqlacodegen/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def __init__(self, table):
173173
for supercls in cls.__mro__:
174174
if hasattr(supercls, '__visit_name__'):
175175
cls = supercls
176-
if supercls.__name__ != supercls.__name__.upper():
176+
if supercls.__name__ != supercls.__name__.upper() and not supercls.__name__.startswith('_'):
177177
break
178178

179179
column.type = column.type.adapt(cls)

test/test_codegen.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sqlalchemy.types import INTEGER, SMALLINT, VARCHAR, NUMERIC
1010
from sqlalchemy.dialects.postgresql.base import BIGINT, DOUBLE_PRECISION, BOOLEAN, ENUM
1111
from sqlalchemy.dialects.mysql.base import TINYINT
12+
from sqlalchemy.dialects.mysql import base as mysql
1213

1314
from sqlacodegen.codegen import CodeGenerator
1415

@@ -124,6 +125,28 @@ def test_column_adaptation(self):
124125
Column('id', BigInteger),
125126
Column('length', Float)
126127
)
128+
""")
129+
130+
def test_mysql_column_types(self):
131+
Table(
132+
'simple_items', self.metadata,
133+
Column('id', mysql.INTEGER),
134+
Column('name', mysql.VARCHAR(255))
135+
)
136+
137+
eq_(self.generate_code(), """\
138+
# coding: utf-8
139+
from sqlalchemy import Column, Integer, MetaData, String, Table
140+
141+
142+
metadata = MetaData()
143+
144+
145+
t_simple_items = Table(
146+
'simple_items', metadata,
147+
Column('id', Integer),
148+
Column('name', String(255))
149+
)
127150
""")
128151

129152
def test_constraints_table(self):

0 commit comments

Comments
 (0)