Thanks for your answer

I messed up the code snippet; forgot the commit.
Please check updated attachment.
   AFAIU, what is going on there is:

-- the code opens the first connection (without a transaction);
-- a new table is created via connection 1;
-- a new row is inserted via connection 1;
-- the code opens another connection, and BEGINs a transaction ;
-- the code draws two copies of the row via connection1 and connection2;
-- the code changes the attribute .foo of the FIRST copy;
-- the code prints the attribute .foo of the SECOND copy that was drawn via
   another transaction, and the value is still 'init' because it isn't
   changed - the code hasn't changed trans_dummy.foo yet.
I intended to illustrate following behavior:

Two instances of the same class with same id; one pulled via a connection (with cache=False); one pulled via a transaction createt from that same connection; --> Commits to the transaction _do_ invalidate the instance pulled via connection (thanks to cache=False); --> Changes to the connection instance _don't_ invalidate the transaction instance;

This asymmetric behavior seems strange to me, since (as far as i understood the code), the transaction object even uses the same cache; it's using the same DBConnection instance, after all.

I use SQLObject for a GUI app, so I need long living instances; transactionally separated. Can I evade manually syncing all the transactions. If not, what's the best way to invalidate a transaction's cache for a given instance/all instances of given class. Are there any docs on this?

regards Herwig Hochleitner
import sqlobject
# Turn off caching so that multiple connections (ie transactions) sync properly
conn = sqlobject.connectionForURI("sqlite:/:memory:", debug=True, logger="database.query", loglevel="debug", cache=False)
class Dummy(sqlobject.SQLObject):
    foo = sqlobject.StringCol()
Dummy.createTable(connection=conn)
Dummy(foo="init", connection=conn)
tr = conn.transaction()
conn_dummy=Dummy.get(1,conn)
trans_dummy=Dummy.get(1,tr)
print "Writing 'connection_val' to connection foo"
conn_dummy.foo = "connection_val"
print "Value of transaction foo: '%s'" % trans_dummy.foo
print "Writing 'transaction_val' to transaction foo"
trans_dummy.foo = "transaction_val"
tr.commit()
print "Value of connection foo: '%s'" % conn_dummy.foo

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to