Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
due to #4287
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 A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
data = Column(String)
bs = relationship("B")
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
aid = Column(ForeignKey('a.id'))
cs = relationship("C")
class C(Base):
__tablename__ = 'c'
id = Column(Integer, primary_key=True)
bid = Column(ForeignKey('b.id'))
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
s = Session(e)
s.add(A(bs=[B(cs=[C()])]))
s.commit()
s.close()
a1 = s.query(A).options(Load(A).lazyload("*")).first()
a1.bs[0].cs
Traceback (most recent call last):
File "test.py", line 40, in <module>
a1.bs[0].cs
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/attributes.py", line 242, in __get__
return self.impl.get(instance_state(instance), dict_)
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/attributes.py", line 599, in get
value = self.callable_(state, passive)
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/strategies.py", line 631, in _load_for_state
session, state, primary_key_identity, passive)
File "<string>", line 1, in <lambda>
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/strategies.py", line 713, in _emit_lazyload
state.load_options, effective_path
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/ext/baked.py", line 185, in _add_lazyload_options
cache_key = opt._generate_cache_key(cache_path)
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/strategy_options.py", line 92, in _generate_cache_key
chopped = self._chop_path(loader_path, path)
File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/strategy_options.py", line 389, in _chop_path
elif c_token.is_mapper and p_token.is_mapper and \
AttributeError: 'str' object has no attribute 'is_mapper'
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Jul 8, 2018
Michael Bayer (@zzzeek) wrote:
https://gerrit.sqlalchemy.org/#/q/I2997ead0b8b9fa0edd009aa6f3161f4618fab97b
sqlalchemy-bot commentedon Jul 9, 2018
Michael Bayer (@zzzeek) wrote:
Check tokens in chop path for inspectionattr before calling is_mapper
Fixed regression in 1.2.9 due to 🎫
4287
where using a:class::
.Load
option in conjunction with a string wildcard would resultin a TypeError.
Change-Id: I2997ead0b8b9fa0edd009aa6f3161f4618fab97b
Fixes: #4298
→ aec5725
sqlalchemy-bot commentedon Jul 9, 2018
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Jul 9, 2018
Michael Bayer (@zzzeek) wrote:
Check tokens in chop path for inspectionattr before calling is_mapper
Fixed regression in 1.2.9 due to 🎫
4287
where using a:class::
.Load
option in conjunction with a string wildcard would resultin a TypeError.
Change-Id: I2997ead0b8b9fa0edd009aa6f3161f4618fab97b
Fixes: #4298
(cherry picked from commit aec5725)
→ dd7d03d