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
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'
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
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
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
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