column_copies = dict()
mapper_args ={}
- propagate = True
table_args = None
+ inherited_table_args = False
tablename = None
for base in cls.__mro__:
- if _is_mapped_class(base):
- propagate = False
- else:
+ if not _is_mapped_class(base):
for name,obj in vars(base).items():
if name == '__mapper_args__':
if not mapper_args:
mapper_args = cls.__mapper_args__
- elif propagate:
- if name == '__table_args__':
- if not table_args:
- table_args = cls.__table_args__
- elif name == '__tablename__':
- if not tablename:
- tablename = cls.__tablename__
- elif base is not cls:
- if isinstance(obj, Column):
- if obj.foreign_keys:
- raise exceptions.InvalidRequestError(
- "Columns with foreign keys to other columns "
- "are not allowed on declarative mixins at this time."
- )
- if name not in dict_:
- dict_[name]=column_copies[obj]=obj.copy()
- elif isinstance(obj, RelationshipProperty):
+ elif name == '__tablename__':
+ if not tablename:
+ tablename = cls.__tablename__
+ elif name == '__table_args__':
+ if not table_args:
+ table_args = cls.__table_args__
+ if base is not cls:
+ inherited_table_args = True
+ elif base is not cls:
+ if isinstance(obj, Column):
+ if obj.foreign_keys:
raise exceptions.InvalidRequestError(
- "relationships are not allowed on "
- "declarative mixins at this time.")
+ "Columns with foreign keys to other columns "
+ "are not allowed on declarative mixins at this time."
+ )
+ if name not in dict_:
+ dict_[name]=column_copies[obj]=obj.copy()
+ elif isinstance(obj, RelationshipProperty):
+ raise exceptions.InvalidRequestError(
+ "relationships are not allowed on "
+ "declarative mixins at this time.")
# make sure that column copies are used rather than the original columns
# from any mixins
if table is None:
# single table inheritance.
# ensure no table args
- if table_args is not None and table_args:
+ if table_args and not inherited_table_args:
raise exceptions.ArgumentError(
"Can't place __table_args__ on an inherited class with no table."
)