eagerloading stops due to recursion check

Issue #659 resolved
Former user created an issue

Having relations A-(1)->B->C, A-(2)->B like

A_table = Table('A', metadata,
            Column('A_id', Integer, primary_key=True),
            Column('a_to_b1', Integer,ForeignKey('B.B_id')), 
            Column('a_to_b2', Integer,ForeignKey('B.B_id')),
)
B_table = Table('B', metadata,
            Column('B_id', Integer, primary_key=True),
            Column('b_to_c', Integer,ForeignKey('C.C_id'))
)
C_table = Table('C', metadata,
            Column('C_id', Integer, primary_key=True)

)

class A(object):pass
class B(object):pass
class C(object):pass

A_mapper = mapper(A, A_table, properties={
   'a_to_b_property1':relation(B_table,primaryjoin = A_table.c.a_to_b1 == B_table.c.B_id),
   'a_to_b_property2':relation(B_table,primaryjoin = A_table.c.a_to_b2 == B_table.c.B_id)
})
B_mapper = mapper(B, B_table, properties={
   'b_to_c_property':relation(C_table)
})
C_mapper = mapper(C, C_table)

I cannot use eagerloading like session.query(A).options(eagerload('a_to_b_property1.b_to_c_property'),eagerload('a_to_b_property2'))...

because context.recursion_stack containts B_mapper after processing a_to_b_property1.b_to_c_property, so a_to_b_property2 skipped and not included in query. To distinct different properties of one mapper, maybe should change stategies.py, line 467 context.recursion_stack.add(self.parent) to context.recursion_stack.add((self.parent,self.key)) and change recursion check too.

Comments (2)

  1. Mike Bayer repo owner

    well this fix was hard won but went spectacularly; as it required a rewrite of how this whole thing worked, eager-loading's methodology got slightly simpler in the process and we got this fix as well as arbitrary levels of joins along self-referential and cyclical relationships, when the option "join_depth" is used. this will be one of the big features in 0.4. changeset:2988

  2. Log in to comment