Hello, I'm experiencing what I think is an unexpected behaviour using
SessionTransaction in SA 0.3.3. The following example is a slightly modified
one from SA's SessionTransaction docs.

#begin sa_example.py
sess = create_session()
trans = sess.create_transaction()

item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)
item1.rep_descrizione=u"one"
item2.rep_descrizione=u"two"

trans.rollback()
trans.close()

print list(sess)
sess.flush()

sess.clear()
sess.close()
sess = create_session()
item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)

print item1.rep_descrizione, item2.rep_descrizione
#end sa_example.py

I don't know if it's a common doubt or if it's just me that didn't
understand something about uow/session behaviour, but I would expect that
objects taken into the query during the transaction to be expunged when
rolling back the transaction, or at least to be taken back to the values
they had when they where pulled from the DB.

Of course I can do around this using an 'external' db transaction:

#begin sa_example.py
conn = engine.connect()
dbtrans = conn.begin()
sess = create_session(bind_to=conn)
#trans = sess.create_transaction()

item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)
item1.rep_descrizione=u"five"
item2.rep_descrizione=u"six"

sess.flush()
dbtrans.rollback()

sess.clear()
sess.close()
sess = create_session()
item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)

print item1.rep_descrizione, item2.rep_descrizione
#end sa_example.py

But then I don't understand what SessionTransaction is there for?

--
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to