- changed component to declarative
- changed milestone to 1.1.x
Single table inheritance attributes are not hidden correctly when mixed with joined table inheritance
Issue #3895
resolved
When mixing single table inheritance and joined table inheritance like this:
class Person(Base):
__tablename__ = "person"
id = Column(Integer, primary_key=True)
type = Column(String)
__mapper_args__ = {
"polymorphic_on": type,
}
class Contractor(Person):
contractor_field = Column(String)
__mapper_args__ = {
"polymorphic_identity": "contractor",
}
class Employee(Person):
__tablename__ = "employee"
id = Column(Integer, ForeignKey(Person.id), primary_key=True)
class Engineer(Employee):
__mapper_args__ = {
"polymorphic_identity": "engineer",
}
instances of Engineer
has access to contractor_field
:
try:
Employee().contractor_field
except AttributeError:
pass # correctly raises
else:
assert False
try:
Engineer().contractor_field
except AttributeError:
pass
else:
assert False # doesn't raise!
Comments (3)
-
repo owner -
repo owner -
repo owner - changed status to resolved
Union the exclude_properties of the inheriting mapper in declarative
Fixed bug where the "automatic exclude" feature of declarative that ensures a column local to a single table inheritance subclass does not appear as an attribute on other derivations of the base would not take effect for multiple levels of subclassing from the base.
Change-Id: Ibf67b631b4870dd1bd159f7d6085549d299fffe0 Fixes:
#3895→ <<cset 9a5943bf76cd>>
- Log in to comment
it looks like this is handled in declarative
if mapping w/ classical mappings, the "contractor_field" will leak into Person if not added to exclude_properties explicitly because it needs to be in the Table that you map to Person, and there's no indication that contractor_field is only for Contractor and not Person otherwise, so the whole "properties are excluded automatically" thing is a declarative feature.