Skip to content

Commit 4e052b9

Browse files
committed
Moved __tablename__ check into main loop for attribute checking
1 parent 4a7a218 commit 4e052b9

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

gino/declarative.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ def _init_table(cls, sub_cls):
152152
for each_cls in sub_cls.__mro__[::-1]:
153153
for k, v in getattr(each_cls, '__namespace__',
154154
each_cls.__dict__).items():
155-
if callable(v) and getattr(v, '__declared_attr__', False):
156-
if k == '__tablename__':
157-
table_name = v(sub_cls)
158-
continue
155+
declared_callable_attr = callable(v) and \
156+
getattr(v, '__declared_attr__', False)
157+
if k != '__tablename__' and declared_callable_attr:
159158
v = updates[k] = v(sub_cls)
159+
elif k == '__tablename__':
160+
table_name = v(sub_cls) if declared_callable_attr else v
160161
if isinstance(v, sa.Column):
161162
v = v.copy()
162163
if not v.name:
@@ -166,9 +167,6 @@ def _init_table(cls, sub_cls):
166167
updates[k] = sub_cls.__attr_factory__(k, v)
167168
elif isinstance(v, (sa.Index, sa.Constraint)):
168169
inspected_args.append(v)
169-
if getattr(sub_cls, '__tablename__', None) and \
170-
not callable(getattr(sub_cls, '__tablename__')):
171-
table_name = getattr(sub_cls, '__tablename__')
172170
if table_name is None:
173171
return
174172
sub_cls._column_name_map = column_name_map

0 commit comments

Comments
 (0)