Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2222 (closed defect: invalid)

Opened 10 years ago

Last modified 10 years ago

Got UnboundExecutionError when the user is loged in and there is exception raised within method with exception_handler

Reported by: victorlin Owned by: Chris Arndt
Priority: normal Milestone: 1.1
Component: TurboGears Version: 1.0.8
Severity: normal Keywords: needs feedback, session, identity, error handler
Cc:

Description (last modified by jorge.vargas) (diff)

Page handler: <function _wrapper at 0x020DF230>
Traceback (most recent call last):
  File "c:\python25\lib\site-packages\cherrypy-2.3.0-py2.5.egg\cherrypy\_cphttptools.py", line 121, in _run
    self.main()
  File "c:\python25\lib\site-packages\cherrypy-2.3.0-py2.5.egg\cherrypy\_cphttptools.py", line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\identity\conditions.py", line 241, in _wrapper
    return fn(*args, **kw)
  File "<string>", line 3, in add
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 360, in expose
    *args, **kw)
  File "<string>", line 5, in run_with_transaction
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\database.py", line 407, in sa_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 373, in <lambda>
    mapping, fragment, args, kw)))
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 410, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\errorhandling.py", line 92, in try_call
    output = dispatch_error(self, func, None, e, *args, **kw)
  File "<string>", line 5, in dispatch_error
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\errorhandling.py", line 69, in adaptor
    return func(controller, *args, **kw)
  File "<string>", line 3, in add_form
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 355, in expose
    *args, **kw)
  File "<string>", line 5, in _expose
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 373, in <lambda>
    mapping, fragment, args, kw)))
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 423, in _execute_func
    return _process_output(output, template, format, content_type, mapping, fragment)
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 88, in _process_output
    fragment=fragment)
  File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\view\base.py", line 159, in render
    return engine.render(**kw)
  File "c:\python25\lib\site-packages\TurboKid-1.0.4-py2.5.egg\turbokid\kidsupport.py", line 206, in render
    output=output, format=format)
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\__init__.py", line 301, in serialize
    raise_template_error(module=self.__module__)
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\__init__.py", line 299, in serialize
    return serializer.serialize(self, encoding, fragment, format)
  File "C:\Python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 107, in serialize
    text = ''.join(self.generate(stream, encoding, fragment, format))
  File "C:\Python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 629, in generate
    for ev, item in self.apply_filters(stream, format):
  File "C:\Python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 165, in format_stream
    for ev, item in stream:
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 221, in _coalesce
    for ev, item in stream:
  File "C:\Python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 477, in inject_meta_tags
    for ev, item in stream:
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 179, in _track
    for p in stream:
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\filter.py", line 41, in apply_matches
    templates[:i] + templates[i+1:], apply_func):
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\filter.py", line 32, in apply_matches
    item = stream.expand()
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 108, in expand
    for ev, item in self._iter:
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 179, in _track
    for p in stream:
  File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 221, in _coalesce
    for ev, item in stream:
  File "I:\projects\amazon_winner\src\trunk\amazon-winner\amazon_winner\templates\super_admin\master.py", line 110, in _match_func
  File "c:\python25\lib\site-packages\SQLAlchemy-0.5.0beta2-py2.5.egg\sqlalchemy\orm\attributes.py", line 123, in __get__
    return self.impl.get(instance_state(instance))
  File "c:\python25\lib\site-packages\SQLAlchemy-0.5.0beta2-py2.5.egg\sqlalchemy\orm\attributes.py", line 307, in get
    value = callable_()
  File "c:\python25\lib\site-packages\SQLAlchemy-0.5.0beta2-py2.5.egg\sqlalchemy\orm\attributes.py", line 870, in __call__
    attr.impl.key in unmodified
  File "c:\python25\lib\site-packages\SQLAlchemy-0.5.0beta2-py2.5.egg\sqlalchemy\orm\mapper.py", line 1602, in _load_scalar_attributes
    raise sa_exc.UnboundExecutionError("Instance %s is not bound to a Session; attribute refresh operation cannot proceed" % (state_str(state)))
UnboundExecutionError: Instance User@0x20e2b30 is not bound to a Session; attribute refresh operation cannot proceed
Error in code generated from template file 'I:\\projects\\amazon_winner\\src\\trunk\\amazon-winner\\amazon_winner\\templates\\super_admin\\user_form.kid'

I use elixir as database backend. I got this error when I login as a user, and I browse some exposed method that raise exception and handled by exception handler. The exception handler's template access identity, namely, a elixir entity. I thought things happen like this.

session created call page handler handle... raise a exception (the session might be closed here) handle error dispatch to error handler session created (another session) call page handler render page, the template access identity object(the session is closed)... Boom!

That's it, I thought the identity create some object with old session is closed when there is a exception raised. And the error handler catch the problem and render it, but the template will display the user information, once it touch the closed session's identity, here comes the error.

But however, that is just a guess. I'm not sure is that correct.

This is the workaround recipe, I enforce the SqlAlchemyIdentity? to return fresh user every time rather than stored one.

    from turbogears.identity import saprovider
    def _get_user(self):
        if self.visit_link is None:
            return None
        return saprovider.user_class.query.get(self.visit_link.user_id)
    saprovider.SqlAlchemyIdentity.user = property(_get_user)

Change History

comment:1 in reply to: ↑ description Changed 10 years ago by victorlin

sorry the description of path of things happen is a mess. I post it again

  1. session created
  2. call page handler
  3. handle...
  4. raise a exception (the session might be closed here)
  5. dispatch to error handler
  6. session created (another session)
  7. call page handler
  8. render page, template access identity object(the session is closed)... Boom!

comment:2 Changed 10 years ago by jorge.vargas

  • Description modified (diff)

comment:3 Changed 10 years ago by Chris Arndt

  • Status changed from new to assigned
  • Owner set to Chris Arndt

I know it is months since this has been reported, but if you are still having this problem, please post a full example exhibiting the problem.

comment:4 Changed 10 years ago by Chris Arndt

  • Keywords needs feedback, session, identity, added; session identity removed

comment:5 Changed 10 years ago by Chris Arndt

  • Status changed from assigned to closed
  • Resolution set to invalid

Closing ticket as invalid because of missing feedback and there is no code to reproduce the error. If you still have this problem, please post to the mailing list with a detailed description and a full test case to demonstrate the problem. Based on this discussion we can then decide whether this ticket should be reopened.

Note: See TracTickets for help on using tickets.