I've had the same problem. I tried creating the session without the ZopeTransactionExtension and found that the Admin UI does not work without it. So I've created two sessions. DBSession has the transaction object, another (called session) does not.
I use session in my code, DBSession just exists for Admin. Seems to work but I do not like this transaction extension thingy and wish it were not part of TG. On May 5, 2010, at 6:40 AM, rajasekhar911 wrote: > Hi > > I am using TG2 in a multithreaded app. > i have some doubts on how to use the session and transaction. > > 1)DBSession is created in the following way > from zope.sqlalchemy import ZopeTransactionExtension > from sqlalchemy.orm import scoped_session, sessionmaker > maker = sessionmaker(autoflush=True, > autocommit=False,expire_on_commit=False, > extension=ZopeTransactionExtension()) > DBSession = scoped_session(maker) > > at some places in my code i need to do a manual commit, so that the > updated data > will be available to all requests. for this i do transaction.commit(). > but after this commit, > if i access the session objects, i get the following error > UnboundExecutionError: Parent instance <Entity at 0x2aaab05251d0> is > not bound to a Session; lazy load operation of attribute 'ha' cannot > proceed > > to avoid this error i re-fetch the obj from db. > is this the way it is supposed to be? > > if i try to do DBSession.commit() it throws an error > Error - exceptions.AssertionError: Transaction must be committed using > the transaction manager > URL: http://127.0.0.1:8091/test > File '/tg2env/lib/python2.4/site-packages/WebError-0.10.1-py2.4.egg/ > weberror/errormiddleware.py', line 162 in __call__ > app_iter = self.application(environ, sr_checker) > File '/tg2env/lib/python2.4/site-packages/TurboGears2-2.0rc1.- > py2.4.egg/tg/configuration.py', line 643 in wrapper > return app(environ, start_response) > File '/tg2env/lib/python2.4/site-packages/TurboGears2-2.0rc1.- > py2.4.egg/tg/configuration.py', line 543 in remover > return app(environ, start_response) > File '/tg2env/lib/python2.4/site-packages/repoze.tm2-1.0a4-py2.4.egg/ > repoze/tm/__init__.py', line 19 in __call__ > result = self.application(environ, save_status_and_headers) > File '/tg2env/lib/python2.4/site-packages/repoze.who-1.0.10-py2.4.egg/ > repoze/who/middleware.py', line 107 in __call__ > app_iter = app(environ, wrapper.wrap_start_response) > File '/tg2env/lib/python2.4/site-packages/ToscaWidgets-0.9.7.2- > py2.4.egg/tw/core/middleware.py', line 36 in __call__ > return self.wsgi_app(environ, start_response) > File '/tg2env/lib/python2.4/site-packages/ToscaWidgets-0.9.7.2- > py2.4.egg/tw/core/middleware.py', line 59 in wsgi_app > resp = req.get_response(self.application) > File 'build/bdist.linux-x86_64/egg/webob/__init__.py', line 1324 in > get_response > File 'build/bdist.linux-x86_64/egg/webob/__init__.py', line 1293 in > call_application > File '/tg2env/lib/python2.4/site-packages/ToscaWidgets-0.9.7.2- > py2.4.egg/tw/core/resource_injector.py', line 67 in _injector > resp = req.get_response(app) > File 'build/bdist.linux-x86_64/egg/webob/__init__.py', line 1324 in > get_response > File 'build/bdist.linux-x86_64/egg/webob/__init__.py', line 1293 in > call_application > File '/tg2env/lib/python2.4/site-packages/Beaker-1.4-py2.4.egg/beaker/ > middleware.py', line 73 in __call__ > return self.app(environ, start_response) > File '/tg2env/lib/python2.4/site-packages/Beaker-1.4-py2.4.egg/beaker/ > middleware.py', line 152 in __call__ > return self.wrap_app(environ, session_start_response) > File '/tg2env/lib/python2.4/site-packages/Routes-1.10.3-py2.4.egg/ > routes/middleware.py', line 130 in __call__ > response = self.app(environ, start_response) > File '/tg2env/lib/python2.4/site-packages/Pylons-0.9.7-py2.4.egg/ > pylons/wsgiapp.py', line 125 in __call__ > response = self.dispatch(controller, environ, start_response) > File '/tg2env/lib/python2.4/site-packages/Pylons-0.9.7-py2.4.egg/ > pylons/wsgiapp.py', line 324 in dispatch > return controller(environ, start_response) > File '/m2svn/trunk/src/convirt/web/convirt/convirt/lib/base.py', line > 32 in __call__ > return TGController.__call__(self, environ, start_response) > File '/tg2env/lib/python2.4/site-packages/Pylons-0.9.7-py2.4.egg/ > pylons/controllers/core.py', line 221 in __call__ > response = self._dispatch_call() > File '/tg2env/lib/python2.4/site-packages/Pylons-0.9.7-py2.4.egg/ > pylons/controllers/core.py', line 172 in _dispatch_call > response = self._inspect_call(func) > File '/tg2env/lib/python2.4/site-packages/Pylons-0.9.7-py2.4.egg/ > pylons/controllers/core.py', line 107 in _inspect_call > result = self._perform_call(func, args) > File '/tg2env/lib/python2.4/site-packages/TurboGears2-2.0rc1.- > py2.4.egg/tg/controllers.py', line 775 in _perform_call > result = DecoratedController._perform_call( > File '/tg2env/lib/python2.4/site-packages/TurboGears2-2.0rc1.- > py2.4.egg/tg/controllers.py', line 142 in _perform_call > output = controller(*remainder, **dict(params)) > File '/m2svn/trunk/src/convirt/web/convirt/convirt/controllers/ > root.py', line 171 in test > DBSession.commit() > File '/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-py2.4.egg/ > sqlalchemy/orm/scoping.py', line 123 in do > return getattr(self.registry(), name)(*args, **kwargs) > File '/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-py2.4.egg/ > sqlalchemy/orm/session.py', line 673 in commit > self.transaction.commit() > File '/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-py2.4.egg/ > sqlalchemy/orm/session.py', line 378 in commit > self._prepare_impl() > File '/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-py2.4.egg/ > sqlalchemy/orm/session.py', line 354 in _prepare_impl > ext.before_commit(self.session) > File '/tg2env/lib/python2.4/site-packages/zope.sqlalchemy-0.4- > py2.4.egg/zope/sqlalchemy/datamanager.py', line 201 in before_commit > assert zope_transaction.get().status == 'Committing', "Transaction > must be committed using the transaction manager" > AssertionError: Transaction must be committed using the transaction > manager > > -- > You received this message because you are subscribed to the Google Groups > "TurboGears" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/turbogears?hl=en. > -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

