[Sqlalchemy-tickets] Issue #4352: Single table inheritance conflict resolution breaks for primary k
Brought to you by:
zzzeek
From: Tom M. <iss...@bi...> - 2018-10-30 01:49:03
|
New issue 4352: Single table inheritance conflict resolution breaks for primary keys https://bitbucket.org/zzzeek/sqlalchemy/issues/4352/single-table-inheritance-conflict Tom Manderson: Single table inheritance has a conflict resolution method for columns that appear in multiple subclasses. When the column that appears in multiple subclasses is a primary key, the conflict resolution procedure is skipped and an error is thrown. This makes sense when the primary key isn't on the base class to start with, but if it is (eg. in my use case the primary key is added with `declared_attr.cascading`) then we should allow it. There's an [existing PR](https://github.com/zzzeek/sqlalchemy/pull/483) including the code below as a test case: ``` class TestBase(Base): __abstract__ = True @declared_attr.cascading def id(cls): col_val = None if TestBase not in cls.__bases__: col_val = cls.__table__.c.get('id') if col_val is None: col_val = Column(Integer, primary_key=True) return col_val class Person(TestBase): """single table base class""" __tablename__ = 'person' class Engineer(Person): """ single table inheritance, no extra cols """ class Manager(Person): """ single table inheritance, no extra cols """ ``` |