Skip to content

Commit

Permalink
Fixed some bugs in should_set_tablename.
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-p committed Apr 24, 2015
1 parent 7883dcb commit a87e4c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions alchy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def should_set_tablename(bases, dct):
if '__tablename__' in dct or '__table__' in dct or '__abstract__' in dct:
return False

if AbstractConcreteBase in bases:
return False

if has_primary_key(dct):
return True

Expand All @@ -171,15 +174,12 @@ def should_set_tablename(bases, dct):
is_concrete)

for base in bases:
if base is AbstractConcreteBase:
return False

if (not is_concrete) and (hasattr(base, '__tablename__') or
hasattr(base, '__table__')):
return False

for name in dir(base):
if not (name in ('query') or
if not (name in ('query',) or name not in dct or
(name.startswith('__') and name.endswith('__'))):
attr = getattr(base, name)
if getattr(attr, 'primary_key', False):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ def test_is_modified(self):
self.assertEqual(record.is_modified(), False)

def test_should_set_tablename(self):
class AA(AbstractConcreteBase, Model):
idx = Column(types.Integer(), primary_key=True)

self.assertEqual(hasattr(AA, '__tablename__'), False)

class AAA(Model):
__abstract__ = True
idx = Column(types.Integer(), primary_key=True)
Expand All @@ -559,6 +564,12 @@ class CCC(BBB):

self.assertEqual(getattr(CCC, '__tablename__'), 'ccc')

class CCC2(BBB):
idx = Column(types.Integer(), primary_key=False)
c2_int = Column(types.Integer())

self.assertEqual(hasattr(CCC2, '__tablename__'), False)

# Joined table inheritance
class DDD(CCC):
idx = Column(types.Integer(), ForeignKey(CCC.idx),
Expand Down

0 comments on commit a87e4c7

Please sign in to comment.