[Sqlalchemy-tickets] Issue #4287: baked cache key generation fails on relationship from subclass (z
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-06-25 04:19:53
|
New issue 4287: baked cache key generation fails on relationship from subclass https://bitbucket.org/zzzeek/sqlalchemy/issues/4287/baked-cache-key-generation-fails-on Michael Bayer: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey('parent.id')) parent = relationship('Parent', backref=backref('children')) type = Column(String(), nullable=False) __mapper_args__ = { 'polymorphic_on': type, } class ChildSubclass1(Child): __tablename__ = 'child_subclass1' id = Column(Integer, ForeignKey('child.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'subclass1', 'polymorphic_load': 'selectin' } class Other(Base): __tablename__ = 'other' id = Column(Integer, primary_key=True) child_subclass_id = Column(Integer, ForeignKey('child_subclass1.id')) child_subclass = relationship('ChildSubclass1', backref=backref('others')) configure_mappers() opt = joinedload( Parent.children.of_type(ChildSubclass1) ).joinedload(ChildSubclass1.others) path = Parent.__mapper__._path_registry[Parent.children.property][Child.__mapper__] print( opt._generate_cache_key(path) ) ``` generates: ``` #!python ((<class '__main__.ChildSubclass1'>, ('lazy', 'joined')),) ``` e.g. not taking "Other" into account. Load._chop_path() is failing. See also #4286 where this was found. |