[sqlalchemy] A transaction is already begun. Use subtransactions=True to allow subtransactions.

2013-01-17 Thread jo
Hi all, I'm running an web application in turbogears1 using sqlalchemy I'm using mainly postgresql as database but in a few installations I'm using oracle (same programs only db change). Using PostgreSQL all is ok but when I use oracle some times I get the following error: File

[sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Derek Litz
Code is below: see NOTE comments from sqlalchemy import create_engine from sqlalchemy import Column, Integer, Unicode from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from contextlib import contextmanager USERNAME = u'root' PASSWORD = u'' LOCAL_DB

Re: [sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Michael Bayer
On Jan 17, 2013, at 10:27 AM, Derek Litz wrote: with mysql_session() as s: new_user = User(first_name=u'Derek') s.add(new_user) s.commit() add_last_name(new_user.id) # NOTE this makes sense, the object was never updated here assert not new_user.last_name == u'Litz'

Re: [sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Derek Litz
So the earlier commit ended the transaction but immediately began a new one, that's why a second call to commit had a different behavior? I made the mistake of thinking that the session would be in a similar state to when I originally acquired it, however, this is not true because I still have

Re: [sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Derek Litz
Yeah, just reading through the logs, they confirm my new understanding :). Thanks much! 2013-01-17 10:09:41,335 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) 2013-01-17 10:09:41,335 INFO sqlalchemy.engine.base.Engine INSERT INTO user (first_name, last_name) VALUES (%s, %s) 2013-01-17

Re: [sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Michael Bayer
the beginning of a transaction is implicit when using the Python DBAPI, typically when the first SQL statement is emitted subsequent to the last commit or rollback. the subtlety in your example, as I look more closely, is that it says: commit() add_last_name(new_user.id) the commit ends the

Re: [sqlalchemy] Using multiple sessions in a single thread, unexpected behavior, stale information: Why?

2013-01-17 Thread Derek Litz
Ah, ha! Thanks much. On Thursday, January 17, 2013 10:16:16 AM UTC-6, Michael Bayer wrote: the beginning of a transaction is implicit when using the Python DBAPI, typically when the first SQL statement is emitted subsequent to the last commit or rollback. the subtlety in your example, as

Re: [sqlalchemy] How to handle 'sub-commits'?

2013-01-17 Thread Ken Lareau
Sadly, it looks like when I try the code in my full application, it is failing miserably. I'm seeing errors like this: sqlalchemy.orm.exc.DetachedInstanceError: Instance Deployments at 0x3367910 is not bound to a Session; attribute refresh operation cannot proceed and

Re: [sqlalchemy] How to handle 'sub-commits'?

2013-01-17 Thread Ken Lareau
On Thu, Jan 17, 2013 at 4:13 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Jan 17, 2013, at 7:01 PM, Ken Lareau wrote: On Thu, Jan 17, 2013 at 3:54 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Jan 17, 2013, at 6:45 PM, Ken Lareau wrote: Sadly, it looks like when I try the

Re: [sqlalchemy] How to handle 'sub-commits'?

2013-01-17 Thread Michael Bayer
On Jan 17, 2013, at 7:24 PM, Ken Lareau wrote: On Thu, Jan 17, 2013 at 4:13 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 17, 2013, at 7:01 PM, Ken Lareau wrote: On Thu, Jan 17, 2013 at 3:54 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 17, 2013, at 6:45

Re: [sqlalchemy] How to handle 'sub-commits'?

2013-01-17 Thread Ken Lareau
On Thu, Jan 17, 2013 at 4:26 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Jan 17, 2013, at 7:24 PM, Ken Lareau wrote: On Thu, Jan 17, 2013 at 4:13 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Jan 17, 2013, at 7:01 PM, Ken Lareau wrote: On Thu, Jan 17, 2013 at 3:54 PM,