Open Jw-F opened 4 years ago
I am running into the same issue: I have an STI model w/ a generic relationship defined on the base class. Subclasses are raising an attribute error post-save.
class Event(Base):
__tablename__ = "events"
actor_type: str = db.Column(db.Text)
actor_id: int = db.Column(db.BigInteger, nullable=False)
@declared_attr
def actor(cls) -> Base:
return generic_relationship("actor_type", "actor_id")
subject_type: str = db.Column(db.Text)
subject_id: int = db.Column(db.BigInteger, nullable=False)
@declared_attr
def subject(cls) -> Base:
return generic_relationship("subject_type", "subject_id")
type: str = db.Column(db.Text, nullable=False)
__mapper_args__ = {
"polymorphic_identity": "events",
"polymorphic_on": type,
}
class TestEventOne(Event):
__mapper_args__ = {
"polymorphic_identity": "test_event_one",
}
I can create and persist a TestEventOne
instance, but any attempt to access attributes raises the AttributeError
mentioned above. I'm able to work around by manually refreshing the instance:
db.session.refresh(event)
I just want to throw in a me too on this. The solution @twelvelabs showed above seems to work, but a fix for this would be great.
I have a Polymorphic model with a generic relationship. After expiring the instance, accessing attributes raises an
AttributeError: columns
.To reproduce:
Traceback:
Version info: