Skip to content

regression in strategy pathing #4298

Closed
Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

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'

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Jul 8, 2018

@sqlalchemy-bot
CollaboratorAuthor
sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2018

@sqlalchemy-bot
CollaboratorAuthor

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 result
in a TypeError.

Change-Id: I2997ead0b8b9fa0edd009aa6f3161f4618fab97b
Fixes: #4298

aec5725

sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2018

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2018

@sqlalchemy-bot
CollaboratorAuthor

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 result
in a TypeError.

Change-Id: I2997ead0b8b9fa0edd009aa6f3161f4618fab97b
Fixes: #4298
(cherry picked from commit aec5725)

dd7d03d

added this to the 1.2.x milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingorm

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          regression in strategy pathing · Issue #4298 · sqlalchemy/sqlalchemy