I am new to TurboGear and I am having some difficulties with the
framewok (which is very cool by the way :).
Each time I try to save an SQLObject in a session; I get an error while
trying to retrieve it after the first request cycle.
I am using the latest SVN version.
#I create the object:
p = Useraccount.select(sqlobject.AND(Useraccount.q.login==login,
Useraccount.q.password==password))
# Save it
cherrypy.session['user'] = p[0]
# but if I try to get it back later on; it breaks:
user = cherrypy.session.get("user", None)
#with below error:
Page handler: <bound method Root.default of
<montecristo.controllers.Root object at 0x2aaaadec4d50>>
Traceback (most recent call last):
File
"/usr/lib64/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py",
line 98, in _run
self.main()
File
"/usr/lib64/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py",
line 246, in main
body = page_handler(*virtual_path, **self.params)
File
"/usr/lib64/python2.4/site-packages/TurboGears-0.9a0dev_r518-py2.4.egg/turbogears/controllers.py",
line 240, in newfunc
html, fragment, *args, **kw)
File
"/usr/lib64/python2.4/site-packages/TurboGears-0.9a0dev_r518-py2.4.egg/turbogears/database.py",
line 189, in run_with_transaction
retval = func(*args, **kw)
File
"/usr/lib64/python2.4/site-packages/TurboGears-0.9a0dev_r518-py2.4.egg/turbogears/controllers.py",
line 262, in _execute_func
return _process_output(tg_format, output, html, fragment)
File
"/usr/lib64/python2.4/site-packages/TurboGears-0.9a0dev_r518-py2.4.egg/turbogears/controllers.py",
line 62, in _process_output
output = view.render(output, tg_format,
template=template,fragment=fragment)
File
"/usr/lib64/python2.4/site-packages/TurboGears-0.9a0dev_r518-py2.4.egg/turbogears/view.py",
line 57, in render
return engine.render(info, format, fragment, template)
File
"/usr/lib64/python2.4/site-packages/TurboKid-0.9.0-py2.4.egg/turbokid/kidsupport.py",
line 136, in render
return t.serialize(encoding=self.defaultencoding, output=format,
fragment=fragment)
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/__init__.py",
line 232, in serialize
return serializer.serialize(self, encoding, fragment)
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/serialization.py",
line 51, in serialize
text = list(self.generate(stream, encoding, fragment))
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/serialization.py",
line 319, in generate
for ev, item in self.apply_filters(stream):
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/serialization.py",
line 77, in balancing_filter
for ev, item in stream:
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/pull.py",
line 203, in _coalesce
for ev, item in stream:
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/filter.py",
line 21, in transform_filter
for ev, item in apply_matches(stream, template, templates,
apply_func):
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/filter.py",
line 37, in apply_matches
apply_func):
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/filter.py",
line 31, in apply_matches
item = stream.expand()
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/pull.py",
line 95, in expand
for ev, item in self._iter:
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/pull.py",
line 164, in _track
for p in stream:
File
"/usr/lib64/python2.4/site-packages/kid-0.8-py2.4.egg/kid/pull.py",
line 203, in _coalesce
for ev, item in stream:
File "/home/test/python/mc/mc/templates/master.py", line 750, in
_match_func
File "<string>", line 1, in <lambda>
File
"/usr/lib64/python2.4/site-packages/SQLObject-0.8dev_r1518-py2.4.egg/sqlobject/main.py",
line 992, in _SO_loadValue
selectResults = self._connection._SO_selectOne(self, dbNames)
File
"/usr/lib64/python2.4/site-packages/SQLObject-0.8dev_r1518-py2.4.egg/sqlobject/dbconnection.py",
line 847, in __getattr__
self.assertActive()
File
"/usr/lib64/python2.4/site-packages/SQLObject-0.8dev_r1518-py2.4.egg/sqlobject/dbconnection.py",
line 788, in assertActive
assert not self._obsolete, "This transaction has already gone
through ROLLBACK; begin another transaction"
AssertionError: This transaction has already gone through ROLLBACK;
begin another transaction
Anyone facing the same kind of issue?
It looks like the SQLObject is not 'synchronized' anymore with the db..
Thanks!
Thanks, and welcome!
>
> Each time I try to save an SQLObject in a session; I get an error while
> trying to retrieve it after the first request cycle.
Nope. You can't put an SQLObject in the session because its data is
considered tied to the transaction it was created in. What you *can*
do, though, is put the ID in the session and then just do
ClassName.get(ID) when you need the data back.
Kevin
And I must add that the mailing list is responsive and helpful. :-)
>Nope. You can't put an SQLObject in the session because its data is
>considered tied to the transaction it was created in. What you *can*
>do, though, is put the ID in the session and then just do
>ClassName.get(ID) when you need the data back.
Ok, I see. Thanks for the clarification!
Yannick