Using sqlalchemy rev 2102
is flush supposed to commit by itself?
Also, looks like Binary fields get flushed every time, even when not changed..
Again, using wsgi middleware to automatically rollback if an exception occurs
in
my app, I have a use case where I absolutely must commit a transaction even if
an exception occurs later.
So I have a set of master/child tables, Shipment -> Package
I have session and a transaction (on which, begin has already been called).
Here's what happens.
now = datetime.datetime.now()
shipment = session.query(Shipment).get_by()
shipment.hash = ''
for package in shipment.packages:
package.void_requested = now
print "FLUSH 1"
session.flush()
print "COMMIT 1"
trans.commit()
# some other non db stuff
package.void_confirmed = now
print "FLUSH 2"
session.flush()
print "COMMIT 2"
trans.commit()
(this causes uow to write out the entire shipment object, including large and
unchanged pickle fields.. then write out package)
FLUSH 1
2006-11-14 21:04:38,532 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
UPDATE shipment SET quote_pickle=?, quote_hash=?, decoded_manifest=?
<snip>
2006-11-14 21:04:38,837 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
UPDATE package SET void_requested=? WHERE package.id = ?
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:UPDATE package SET
void_requested=? WHERE package.id = ?
2006-11-14 21:04:38,838 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
[datetime.datetime(2006, 11, 14, 21, 4, 38, 518976), 200]
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:[datetime.datetime(2006, 11,
14, 21, 4, 38, 518976), 200]
COMMIT 1
2006-11-14 21:04:38,850 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
COMMIT
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:COMMIT
And then comes FLUSH2, like so:
FLUSH 2
2006-11-14 21:04:39,544 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94 BEGIN
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:BEGIN
2006-11-14 21:04:39,551 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
UPDATE shipment SET quote_pickle=?, decoded_manifest=? WHERE shipment.id = ?
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:UPDATE shipment SET
quote_pickle=?, decoded_manifest=? WHERE shipment.id = ?
(here it is, again writing out these unchanged shipment fields, shipment hasn't
been touched between the 2 flushes)
2006-11-14 21:04:39,750 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
UPDATE package SET void_confirmed=? WHERE package.id = ?
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:UPDATE package SET
void_confirmed=? WHERE package.id = ?
2006-11-14 21:04:39,750 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
[datetime.datetime(2006, 11, 14, 21, 4, 39, 541557), 200]
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:[datetime.datetime(2006, 11,
14, 21, 4, 39, 541557), 200]
2006-11-14 21:04:39,755 INFO sqlalchemy.engine.threadlocal.TLEngine.0x..94
COMMIT
INFO:sqlalchemy.engine.threadlocal.TLEngine.0x..94:COMMIT
(see above, flush did a commit by itself)
COMMIT 2
File '/usr/local/src/sqlalchemy/lib/sqlalchemy/engine/base.py', line 389 in
commit
raise exceptions.InvalidRequestError("This transaction is inactive")
InvalidRequestError: This transaction is inactive
engine strategy is threadlocal.
Is this the way it's supposed to work?
--
Brad Clements, [EMAIL PROTECTED] (315)268-1000
http://www.murkworks.com
AOL-IM or SKYPE: BKClements
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users