Hi, Michael Bayer.
Thanks, that example is really helpful.
In your example I used Session.object_session method to verify that
main_method and method1 running in two different sessions.
But my test result showing that main_method and method1 running in same session.
I think, we can check this using
method Session.object_session , I am not sure about that.
* added following code in main_method
s1 = Session.object_session(db_obj1)
print "=======main_method====session=====", vars(s1)
* added following code in method1
s2 = Session.object_session(db_obj2)
print "=======method1====session=====", vars(s2)
Result
=========
=======main_method====session===== " {'autocommit': False, 'autoflush': True, 'transaction': <sqlalchemy.orm.session.SessionTransaction object at 0x22a5f90>,
'hash_key': 36330896,
'expire_on_commit': True, '_new': {}, 'bind':
Engine(mysql://root:cvt@localhost/cvt_ee), '_deleted': {},
'_flushing': False, 'identity_map': {(<class '__main__.A'>,
(1L,)): <sqlalchemy.orm.state.InstanceState object at 0x22a5c90>},
'_enable_transaction_accounting': True, 'extensions': [],
'_identity_cls': <class
'sqlalchemy.orm.identity.WeakInstanceDict'>, 'twophase': False,
'_Session__binds': {}, '_query_cls': <class
'sqlalchemy.orm.query.Query'>, '_mapper_flush_opts': {}}
=======method1====session===== {'autocommit': False, 'autoflush': True, 'transaction': <sqlalchemy.orm.session.SessionTransaction object at 0x2073190>,
'hash_key': 36330896,
'expire_on_commit': True, '_new': {}, 'bind':
Engine(mysql://root:cvt@localhost/cvt_ee), '_deleted': {},
'_flushing': False, 'identity_map': {(<class '__main__.A'>,
(2L,)): <sqlalchemy.orm.state.InstanceState object at 0x2073550>,
(<class '__main__.A'>, (1L,)):
<sqlalchemy.orm.state.InstanceState object at 0x22a5c90>},
'_enable_transaction_accounting': True, 'extensions': [],
'_identity_cls': <class
'sqlalchemy.orm.identity.WeakInstanceDict'>, 'twophase': False,
'_Session__binds': {}, '_query_cls': <class
'sqlalchemy.orm.query.Query'>, '_mapper_flush_opts': {}}