<p dir="auto"><strong>Migrated issue, originally created by Whitney Young (<a href="https://github.com/wbyoung">@wbyoung</a>)</strong></p>
<p dir="auto">Given the following relations:</p>
<ul dir="auto">
<li><code class="notranslate">Company</code> has many <code class="notranslate">employees</code> and a <code class="notranslate">parent</code> company</li>
<li><code class="notranslate">Employee</code> has an <code class="notranslate">employer</code></li>
</ul>
<p dir="auto">And the following instances:</p>
<ul dir="auto">
<li>Apple w/ employees Tim Cook &amp; Jony Ive</li>
<li>Beats w/ employees Dr. Dre &amp; Jimmy Iovine</li>
</ul>
<p dir="auto">The following query does not load everything:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="employees = session.query(Employee).options(
    joinedload('employer').joinedload('parent').subqueryload('employees')
).filter().all()"><pre class="notranslate"><span class="pl-s1">employees</span> <span class="pl-c1">=</span> <span class="pl-s1">session</span>.<span class="pl-en">query</span>(<span class="pl-v">Employee</span>).<span class="pl-en">options</span>(
    <span class="pl-en">joinedload</span>(<span class="pl-s">'employer'</span>).<span class="pl-en">joinedload</span>(<span class="pl-s">'parent'</span>).<span class="pl-en">subqueryload</span>(<span class="pl-s">'employees'</span>)
).<span class="pl-en">filter</span>().<span class="pl-en">all</span>()</pre></div>
<p dir="auto">It appears that it finds all employees and parents properly, but since all the companies get loaded into the session via the joined load, it seems to stop processing at this point and doesn't actually perform the subqueryload of <code class="notranslate">employees</code>. This example may seem contrived since it's circling back around through the relationships, but it's a simplified version of something that w/ filters applied is a very real query in our system.</p>
<p dir="auto">Below is some code to run to show the problem. Just change the connection string to be able to connect to your database, the code will populate a few records for you.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import logging
from contextlib import contextmanager
from sqlalchemy import (
    Column,
    ForeignKey,
    Integer,
    MetaData,
    String,
    Table,
    create_engine,
    inspect,
)
from sqlalchemy.orm import (
    mapper,
    relationship,
    sessionmaker,
    subqueryload,
    joinedload,
)

class Model(object):
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)
class Company(Model): pass
class Employee(Model): pass

engine = create_engine(
    'mysql+pymysql://root:password@localhost/test?charset=utf8mb4',
    convert_unicode=True,
)
metadata = MetaData(bind=engine)
Session = sessionmaker(bind=engine)

company_table = Table(
    'companies', metadata,
    Column('id', Integer, primary_key=True, autoincrement=True),
    Column('name', String(255)),
    Column('parent_id', Integer, ForeignKey('companies.id')),
)
employee_table = Table(
    'employees', metadata,
    Column('id', Integer, primary_key=True, autoincrement=True),
    Column('name', String(255)),
    Column('employer_id', Integer, ForeignKey('companies.id')),
)
company_mapper = mapper(Company, company_table, properties={
    'parent': relationship(
        Company,
        uselist=False,
        remote_side=[company_table.columns.id],
    ),
    'employees': relationship(
        Employee,
        uselist=True,
        back_populates='employer',
    ),
})

employee_mapper = mapper(Employee, employee_table, properties={
    'employer': relationship(
        Company,
        uselist=False,
        back_populates='employees',
    )
})

connection = engine.connect()
metadata.create_all(connection)
connection.close()

@contextmanager
def session_manager():
    session = Session()
    try: yield session; session.commit()
    except: session.rollback(); raise
    finally: session.close()

def _ensure_loaded(obj, key_path):
    components = key_path.split('.')
    for i, key in enumerate(components):
        if key in inspect(obj).unloaded:
            raise AttributeError('Attribute {} not loaded during query'.format(
                '.'.join(components[:i+1])
            ))
        obj = getattr(obj, key)

        if obj is None:
            break

models = [
    Company(id=1, name='Apple'),
    Company(id=2, name='Beats', parent_id=1),
    Employee(id=1, name='Tim Cook', employer_id=1),
    Employee(id=2, name='Jony Ive', employer_id=1),
    Employee(id=3, name='Dr. Dre', employer_id=2),
    Employee(id=4, name='Jimmy Iovine', employer_id=2),
]

for model in models:
    with session_manager() as session:
        try:
            session.add(model)
            session.commit()
        except Exception as e: session.close()

logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

with session_manager() as session:
    employees = session.query(Employee).options(
        joinedload('employer').joinedload('parent').subqueryload('employees')
    ).filter(Employee.id == 3).all()

    for employee in employees:
        _ensure_loaded(employee, 'employer.parent.employees')

# this block of code fails presumably because the parent employer is loaded into the session during
# the first joinedload of the employer which doesn't trigger the subqueryload for parent.employees
# for the company that actually does have a parent company.
with session_manager() as session:
    employees = session.query(Employee).options(
        joinedload('employer').joinedload('parent').subqueryload('employees')
    ).filter().all()

    for employee in employees:
        _ensure_loaded(employee, 'employer.parent.employees')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">logging</span>
<span class="pl-k">from</span> <span class="pl-s1">contextlib</span> <span class="pl-k">import</span> <span class="pl-s1">contextmanager</span>
<span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span> <span class="pl-k">import</span> (
    <span class="pl-v">Column</span>,
    <span class="pl-v">ForeignKey</span>,
    <span class="pl-v">Integer</span>,
    <span class="pl-v">MetaData</span>,
    <span class="pl-v">String</span>,
    <span class="pl-v">Table</span>,
    <span class="pl-s1">create_engine</span>,
    <span class="pl-s1">inspect</span>,
)
<span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">orm</span> <span class="pl-k">import</span> (
    <span class="pl-s1">mapper</span>,
    <span class="pl-s1">relationship</span>,
    <span class="pl-s1">sessionmaker</span>,
    <span class="pl-s1">subqueryload</span>,
    <span class="pl-s1">joinedload</span>,
)

<span class="pl-k">class</span> <span class="pl-v">Model</span>(<span class="pl-s1">object</span>):
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-k">for</span> <span class="pl-s1">key</span>, <span class="pl-s1">value</span> <span class="pl-c1">in</span> <span class="pl-s1">kwargs</span>.<span class="pl-en">items</span>():
            <span class="pl-en">setattr</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
<span class="pl-k">class</span> <span class="pl-v">Company</span>(<span class="pl-v">Model</span>): <span class="pl-k">pass</span>
<span class="pl-k">class</span> <span class="pl-v">Employee</span>(<span class="pl-v">Model</span>): <span class="pl-k">pass</span>

<span class="pl-s1">engine</span> <span class="pl-c1">=</span> <span class="pl-en">create_engine</span>(
    <span class="pl-s">'mysql+pymysql://root:password@localhost/test?charset=utf8mb4'</span>,
    <span class="pl-s1">convert_unicode</span><span class="pl-c1">=</span><span class="pl-c1">True</span>,
)
<span class="pl-s1">metadata</span> <span class="pl-c1">=</span> <span class="pl-v">MetaData</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-s1">engine</span>)
<span class="pl-v">Session</span> <span class="pl-c1">=</span> <span class="pl-en">sessionmaker</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-s1">engine</span>)

<span class="pl-s1">company_table</span> <span class="pl-c1">=</span> <span class="pl-v">Table</span>(
    <span class="pl-s">'companies'</span>, <span class="pl-s1">metadata</span>,
    <span class="pl-v">Column</span>(<span class="pl-s">'id'</span>, <span class="pl-v">Integer</span>, <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">autoincrement</span><span class="pl-c1">=</span><span class="pl-c1">True</span>),
    <span class="pl-v">Column</span>(<span class="pl-s">'name'</span>, <span class="pl-v">String</span>(<span class="pl-c1">255</span>)),
    <span class="pl-v">Column</span>(<span class="pl-s">'parent_id'</span>, <span class="pl-v">Integer</span>, <span class="pl-v">ForeignKey</span>(<span class="pl-s">'companies.id'</span>)),
)
<span class="pl-s1">employee_table</span> <span class="pl-c1">=</span> <span class="pl-v">Table</span>(
    <span class="pl-s">'employees'</span>, <span class="pl-s1">metadata</span>,
    <span class="pl-v">Column</span>(<span class="pl-s">'id'</span>, <span class="pl-v">Integer</span>, <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">autoincrement</span><span class="pl-c1">=</span><span class="pl-c1">True</span>),
    <span class="pl-v">Column</span>(<span class="pl-s">'name'</span>, <span class="pl-v">String</span>(<span class="pl-c1">255</span>)),
    <span class="pl-v">Column</span>(<span class="pl-s">'employer_id'</span>, <span class="pl-v">Integer</span>, <span class="pl-v">ForeignKey</span>(<span class="pl-s">'companies.id'</span>)),
)
<span class="pl-s1">company_mapper</span> <span class="pl-c1">=</span> <span class="pl-en">mapper</span>(<span class="pl-v">Company</span>, <span class="pl-s1">company_table</span>, <span class="pl-s1">properties</span><span class="pl-c1">=</span>{
    <span class="pl-s">'parent'</span>: <span class="pl-en">relationship</span>(
        <span class="pl-v">Company</span>,
        <span class="pl-s1">uselist</span><span class="pl-c1">=</span><span class="pl-c1">False</span>,
        <span class="pl-s1">remote_side</span><span class="pl-c1">=</span>[<span class="pl-s1">company_table</span>.<span class="pl-s1">columns</span>.<span class="pl-s1">id</span>],
    ),
    <span class="pl-s">'employees'</span>: <span class="pl-en">relationship</span>(
        <span class="pl-v">Employee</span>,
        <span class="pl-s1">uselist</span><span class="pl-c1">=</span><span class="pl-c1">True</span>,
        <span class="pl-s1">back_populates</span><span class="pl-c1">=</span><span class="pl-s">'employer'</span>,
    ),
})

<span class="pl-s1">employee_mapper</span> <span class="pl-c1">=</span> <span class="pl-en">mapper</span>(<span class="pl-v">Employee</span>, <span class="pl-s1">employee_table</span>, <span class="pl-s1">properties</span><span class="pl-c1">=</span>{
    <span class="pl-s">'employer'</span>: <span class="pl-en">relationship</span>(
        <span class="pl-v">Company</span>,
        <span class="pl-s1">uselist</span><span class="pl-c1">=</span><span class="pl-c1">False</span>,
        <span class="pl-s1">back_populates</span><span class="pl-c1">=</span><span class="pl-s">'employees'</span>,
    )
})

<span class="pl-s1">connection</span> <span class="pl-c1">=</span> <span class="pl-s1">engine</span>.<span class="pl-en">connect</span>()
<span class="pl-s1">metadata</span>.<span class="pl-en">create_all</span>(<span class="pl-s1">connection</span>)
<span class="pl-s1">connection</span>.<span class="pl-en">close</span>()

<span class="pl-en">@<span class="pl-s1">contextmanager</span></span>
<span class="pl-k">def</span> <span class="pl-en">session_manager</span>():
    <span class="pl-s1">session</span> <span class="pl-c1">=</span> <span class="pl-v">Session</span>()
    <span class="pl-k">try</span>: <span class="pl-k">yield</span> <span class="pl-s1">session</span>; <span class="pl-s1">session</span>.<span class="pl-en">commit</span>()
    <span class="pl-k">except</span>: <span class="pl-s1">session</span>.<span class="pl-en">rollback</span>(); <span class="pl-k">raise</span>
    <span class="pl-k">finally</span>: <span class="pl-s1">session</span>.<span class="pl-en">close</span>()

<span class="pl-k">def</span> <span class="pl-en">_ensure_loaded</span>(<span class="pl-s1">obj</span>, <span class="pl-s1">key_path</span>):
    <span class="pl-s1">components</span> <span class="pl-c1">=</span> <span class="pl-s1">key_path</span>.<span class="pl-en">split</span>(<span class="pl-s">'.'</span>)
    <span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">key</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">components</span>):
        <span class="pl-k">if</span> <span class="pl-s1">key</span> <span class="pl-c1">in</span> <span class="pl-en">inspect</span>(<span class="pl-s1">obj</span>).<span class="pl-s1">unloaded</span>:
            <span class="pl-k">raise</span> <span class="pl-v">AttributeError</span>(<span class="pl-s">'Attribute {} not loaded during query'</span>.<span class="pl-en">format</span>(
                <span class="pl-s">'.'</span>.<span class="pl-en">join</span>(<span class="pl-s1">components</span>[:<span class="pl-s1">i</span><span class="pl-c1">+</span><span class="pl-c1">1</span>])
            ))
        <span class="pl-s1">obj</span> <span class="pl-c1">=</span> <span class="pl-en">getattr</span>(<span class="pl-s1">obj</span>, <span class="pl-s1">key</span>)

        <span class="pl-k">if</span> <span class="pl-s1">obj</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
            <span class="pl-k">break</span>

<span class="pl-s1">models</span> <span class="pl-c1">=</span> [
    <span class="pl-v">Company</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Apple'</span>),
    <span class="pl-v">Company</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">2</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Beats'</span>, <span class="pl-s1">parent_id</span><span class="pl-c1">=</span><span class="pl-c1">1</span>),
    <span class="pl-v">Employee</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Tim Cook'</span>, <span class="pl-s1">employer_id</span><span class="pl-c1">=</span><span class="pl-c1">1</span>),
    <span class="pl-v">Employee</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">2</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Jony Ive'</span>, <span class="pl-s1">employer_id</span><span class="pl-c1">=</span><span class="pl-c1">1</span>),
    <span class="pl-v">Employee</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">3</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Dr. Dre'</span>, <span class="pl-s1">employer_id</span><span class="pl-c1">=</span><span class="pl-c1">2</span>),
    <span class="pl-v">Employee</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-c1">4</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'Jimmy Iovine'</span>, <span class="pl-s1">employer_id</span><span class="pl-c1">=</span><span class="pl-c1">2</span>),
]

<span class="pl-k">for</span> <span class="pl-s1">model</span> <span class="pl-c1">in</span> <span class="pl-s1">models</span>:
    <span class="pl-k">with</span> <span class="pl-en">session_manager</span>() <span class="pl-k">as</span> <span class="pl-s1">session</span>:
        <span class="pl-k">try</span>:
            <span class="pl-s1">session</span>.<span class="pl-en">add</span>(<span class="pl-s1">model</span>)
            <span class="pl-s1">session</span>.<span class="pl-en">commit</span>()
        <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>: <span class="pl-s1">session</span>.<span class="pl-en">close</span>()

<span class="pl-s1">logging</span>.<span class="pl-en">basicConfig</span>()
<span class="pl-s1">logging</span>.<span class="pl-en">getLogger</span>(<span class="pl-s">'sqlalchemy.engine'</span>).<span class="pl-en">setLevel</span>(<span class="pl-s1">logging</span>.<span class="pl-v">INFO</span>)

<span class="pl-k">with</span> <span class="pl-en">session_manager</span>() <span class="pl-k">as</span> <span class="pl-s1">session</span>:
    <span class="pl-s1">employees</span> <span class="pl-c1">=</span> <span class="pl-s1">session</span>.<span class="pl-en">query</span>(<span class="pl-v">Employee</span>).<span class="pl-en">options</span>(
        <span class="pl-en">joinedload</span>(<span class="pl-s">'employer'</span>).<span class="pl-en">joinedload</span>(<span class="pl-s">'parent'</span>).<span class="pl-en">subqueryload</span>(<span class="pl-s">'employees'</span>)
    ).<span class="pl-en">filter</span>(<span class="pl-v">Employee</span>.<span class="pl-s1">id</span> <span class="pl-c1">==</span> <span class="pl-c1">3</span>).<span class="pl-en">all</span>()

    <span class="pl-k">for</span> <span class="pl-s1">employee</span> <span class="pl-c1">in</span> <span class="pl-s1">employees</span>:
        <span class="pl-en">_ensure_loaded</span>(<span class="pl-s1">employee</span>, <span class="pl-s">'employer.parent.employees'</span>)

<span class="pl-c"># this block of code fails presumably because the parent employer is loaded into the session during</span>
<span class="pl-c"># the first joinedload of the employer which doesn't trigger the subqueryload for parent.employees</span>
<span class="pl-c"># for the company that actually does have a parent company.</span>
<span class="pl-k">with</span> <span class="pl-en">session_manager</span>() <span class="pl-k">as</span> <span class="pl-s1">session</span>:
    <span class="pl-s1">employees</span> <span class="pl-c1">=</span> <span class="pl-s1">session</span>.<span class="pl-en">query</span>(<span class="pl-v">Employee</span>).<span class="pl-en">options</span>(
        <span class="pl-en">joinedload</span>(<span class="pl-s">'employer'</span>).<span class="pl-en">joinedload</span>(<span class="pl-s">'parent'</span>).<span class="pl-en">subqueryload</span>(<span class="pl-s">'employees'</span>)
    ).<span class="pl-en">filter</span>().<span class="pl-en">all</span>()

    <span class="pl-k">for</span> <span class="pl-s1">employee</span> <span class="pl-c1">in</span> <span class="pl-s1">employees</span>:
        <span class="pl-en">_ensure_loaded</span>(<span class="pl-s1">employee</span>, <span class="pl-s">'employer.parent.employees'</span>)</pre></div>
<p dir="auto"><strong>Migrated issue, originally created by Kent Rakip (<a href="https://github.com/krakip">@krakip</a>)</strong></p>
<p dir="auto">When a <code class="notranslate">joinedload</code> path causes any entity in a one-to-many relationship to be eagerly loaded, any <code class="notranslate">subqueryload</code> path for the same relationship will not be emitted, even if it might return additional results.</p>
<p dir="auto">Here is a minimal repro case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy import Column, ForeignKey, Integer, create_engine, inspect
from sqlalchemy.orm import relationship, sessionmaker, joinedload
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


class Thing(Base):
    __tablename__ = 'Thing'

    id = Column(Integer, primary_key=True, autoincrement=True)
    another_thing_id = Column(ForeignKey('AnotherThing.id'))
    another_thing = relationship('AnotherThing')

    yet_another_thing_id = Column(ForeignKey('YetAnotherThing.id'))
    yet_another_thing = relationship('YetAnotherThing')


class AnotherThing(Base):
    __tablename__ = 'AnotherThing'

    id = Column(Integer, primary_key=True, autoincrement=True)


class YetAnotherThing(Base):
    __tablename__ = 'YetAnotherThing'

    id = Column(Integer, primary_key=True, autoincrement=True)

    another_thing_id = Column(ForeignKey('AnotherThing.id'))
    another_thing = relationship('AnotherThing', backref='yet_another_things')
    last_thing_id = Column(ForeignKey('LastThing.id'))
    last_thing = relationship('LastThing')


class LastThing(Base):
    __tablename__ = 'LastThing'

    id = Column(Integer, primary_key=True, autoincrement=True)


engine = create_engine('sqlite:///', echo=True)
Base.metadata.create_all(engine)
session_factory = sessionmaker(bind=engine)

session = session_factory()

thing = Thing()
thing.another_thing = AnotherThing()
thing.another_thing.yet_another_things = [YetAnotherThing(), YetAnotherThing()]
thing.yet_another_thing = thing.another_thing.yet_another_things[0]
thing.another_thing.yet_another_things[0].last_thing = LastThing()
thing.another_thing.yet_another_things[1].last_thing = LastThing()

session.add(thing)
session.commit()

session2 = session_factory()

t = (
    session2.query(Thing)
        .options(
            joinedload(Thing.another_thing)
                .subqueryload(AnotherThing.yet_another_things)
                .joinedload(YetAnotherThing.last_thing),
            joinedload(Thing.yet_another_thing)
                .joinedload(YetAnotherThing.another_thing),
        )
        .get(1)
)

# Should print 'False'; actually prints 'True' on 1.1.4
print('yet_another_things' in inspect(t.another_thing).unloaded)"><pre class="notranslate"><code class="notranslate">from sqlalchemy import Column, ForeignKey, Integer, create_engine, inspect
from sqlalchemy.orm import relationship, sessionmaker, joinedload
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


class Thing(Base):
    __tablename__ = 'Thing'

    id = Column(Integer, primary_key=True, autoincrement=True)
    another_thing_id = Column(ForeignKey('AnotherThing.id'))
    another_thing = relationship('AnotherThing')

    yet_another_thing_id = Column(ForeignKey('YetAnotherThing.id'))
    yet_another_thing = relationship('YetAnotherThing')


class AnotherThing(Base):
    __tablename__ = 'AnotherThing'

    id = Column(Integer, primary_key=True, autoincrement=True)


class YetAnotherThing(Base):
    __tablename__ = 'YetAnotherThing'

    id = Column(Integer, primary_key=True, autoincrement=True)

    another_thing_id = Column(ForeignKey('AnotherThing.id'))
    another_thing = relationship('AnotherThing', backref='yet_another_things')
    last_thing_id = Column(ForeignKey('LastThing.id'))
    last_thing = relationship('LastThing')


class LastThing(Base):
    __tablename__ = 'LastThing'

    id = Column(Integer, primary_key=True, autoincrement=True)


engine = create_engine('sqlite:///', echo=True)
Base.metadata.create_all(engine)
session_factory = sessionmaker(bind=engine)

session = session_factory()

thing = Thing()
thing.another_thing = AnotherThing()
thing.another_thing.yet_another_things = [YetAnotherThing(), YetAnotherThing()]
thing.yet_another_thing = thing.another_thing.yet_another_things[0]
thing.another_thing.yet_another_things[0].last_thing = LastThing()
thing.another_thing.yet_another_things[1].last_thing = LastThing()

session.add(thing)
session.commit()

session2 = session_factory()

t = (
    session2.query(Thing)
        .options(
            joinedload(Thing.another_thing)
                .subqueryload(AnotherThing.yet_another_things)
                .joinedload(YetAnotherThing.last_thing),
            joinedload(Thing.yet_another_thing)
                .joinedload(YetAnotherThing.another_thing),
        )
        .get(1)
)

# Should print 'False'; actually prints 'True' on 1.1.4
print('yet_another_things' in inspect(t.another_thing).unloaded)
</code></pre></div>
<p dir="auto">The query that should load all of the values for <code class="notranslate">AnotherThing.yet_another_things</code> is never emitted, and as a result <code class="notranslate">last_thing</code> is not loaded for any of the <code class="notranslate">YetAnotherThing</code>s either, since that occurs later on the same path. Commenting out the second <code class="notranslate">joinedload</code> path causes the <code class="notranslate">subqueryload</code> query to be emitted correctly.</p>
<p dir="auto">This seems to be a regression in 1.1; I'm unable to reproduce it on 1.0.16, although it is possible that the behavior is nondeterministic and I never got lucky.</p>