Hi Everyone,

We are trying to switch to expire_on_commit=False in our project and our tests 
started to fail on the following scenario.

Our best guess is that the attribute is lazy loaded on first access and it is 
not refresh/expired when the relationships change.

Any good suggestions ?


## Modelclass Parent(Base):
    id = sqlalchemy.Column(sqlalchemy.Integer(), primary_key=True, 
autoincrement=True)
    childs = sqlalchemy.orm.relationship("Child", 
primaryjoin="or_(Child.father_id==Parent.id, Child.mother_id==Parent.id)")
class Child(Base):
    id = Column(sqlalchemy.Integer(), primary_key=True, autoincrement=True)
    father_id = sqlalchemy.Column(sqlalchemy.Integer(), 
sqlalchemy.ForeignKey('parents.id'))
    mother_id = sqlalchemy.Column(sqlalchemy.Integer(), 
sqlalchemy.ForeignKey('parents.id'))
    
    father = sqlalchemy.orm.relationship("Parent", foreign_keys=[father_id])
    mother = sqlalchemy.orm.relationship("Parent", foreign_keys=[mother_id])
## Test Code
father = Parent()assert len(father.childs) == 0 # SUCCESS

mother = Parent()
c1 = Child(father=father, mother=mother)assert c1.father is father              
# SUCCESS

session.add_all([father, mother, c1])
session.commit()
# Using refresh solves the assertion#session.refresh(father)            
assert len(father.childs) > 0   # FAILassert father.childs == [c1]      # FAIL

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to