Hello all:


We are running into an issue while using history_meta.py 
(examples/versioned_history). 


I am running test_versioning.py (via sqla_nose) but I am confused about 
test_relationship unit-test.


It asserts sc.version == 3 without an intermediate sess.commit() ... why 
would the version changed before commit (i.e. what triggers the hook for 
the event before_flush in this test-case)?


See 
https://github.com/zzzeek/sqlalchemy/blob/master/examples/versioned_history/test_versioning.py#L556-L577


def test_relationship(self):
class SomeRelated(self.Base, ComparableEntity):
__tablename__ = 'somerelated'
id = Column(Integer, primary_key=True)
class SomeClass(Versioned, self.Base, ComparableEntity):
__tablename__ = 'sometable'
id = Column(Integer, primary_key=True)
name = Column(String(50))
related_id = Column(Integer, ForeignKey('somerelated.id'))
related = relationship("SomeRelated", backref='classes')
SomeClassHistory = SomeClass.__history_mapper__.class_
self.create_tables()
sess = self.session
sc = SomeClass(name='sc1')
sess.add(sc)
sess.commit()
assert sc.version == 1
sr1 = SomeRelated()
sc.related = sr1
sess.commit()
assert sc.version == 2
eq_(
sess.query(SomeClassHistory).filter(
SomeClassHistory.version == 1).all(),
[SomeClassHistory(version=1, name='sc1', related_id=None)]
)
sc.related = None
eq_(
sess.query(SomeClassHistory).order_by(
SomeClassHistory.version).all(),
[
SomeClassHistory(version=1, name='sc1', related_id=None),
SomeClassHistory(version=2, name='sc1', related_id=sr1.id)
]
)
assert sc.version == 3

Line 566 alters the relationship but there is no commit ... however, query 
on history tables reveals version changes even though there was no 
commit/flush in between. 


As far as I understand the versioned_history recipe, version (rows in 
history tables) are created when event 'before_flush' is triggered. 


Does such event trigger when sess.query(SomeClassHistory)... is called?

... It seems like it but why? 


Any help is very much appreciated

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to