Skip to content

Commit deedc36

Browse files
committed
Made the column adaptation code overrideable
1 parent 4f58dbf commit deedc36

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

sqlacodegen/codegen.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,27 @@ def __init__(self, table):
109109

110110
# Adapt column types to the most reasonable generic types (ie. VARCHAR -> String)
111111
for column in table.columns:
112-
coltype = column.type
113-
for supercls in coltype.__class__.__mro__:
114-
if (not supercls.__name__.startswith('_') and
115-
supercls.__name__ != supercls.__name__.upper() and
116-
hasattr(supercls, '__visit_name__')):
112+
column.type = self._get_adapted_type(column.type)
117113

118-
# Hack to fix adaptation of the Enum class which is broken since SQLAlchemy 1.2
119-
kw = {}
120-
if supercls is Enum:
121-
kw['name'] = column.type.name
114+
def _get_adapted_type(self, coltype):
115+
for supercls in coltype.__class__.__mro__:
116+
if (not supercls.__name__.startswith('_') and
117+
supercls.__name__ != supercls.__name__.upper() and
118+
hasattr(supercls, '__visit_name__')):
122119

123-
column.type = column.type.adapt(supercls)
120+
# Hack to fix adaptation of the Enum class which is broken since SQLAlchemy 1.2
121+
kw = {}
122+
if supercls is Enum:
123+
kw['name'] = coltype.name
124124

125-
for key, value in kw.items():
126-
setattr(column.type, key, value)
125+
coltype = coltype.adapt(supercls)
127126

128-
break
127+
for key, value in kw.items():
128+
setattr(coltype, key, value)
129+
130+
break
131+
132+
return coltype
129133

130134
def add_imports(self, collector):
131135
if self.table.columns:

0 commit comments

Comments
 (0)