Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

session_transaction does not setup request #632

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
Contributor

soulseekah commented Nov 10, 2012

session_transaction() is failing to initialize the request by calling before_request, but is successfully calling the teardown functions, resulting in objects that have never been created to be accessed. This additional test also makes 11 other tests fail because of some stack corruption after the new test fails.

Patch pending.

@soulseekah soulseekah session_transaction failing test
session_transaction() is failing to initialize the request by
calling before_request, but is successfully calling the teardown
functions, resulting in objects that have never been created to
be accessed. This additional test also makes 11 other tests fail
because of some stack corruption after the new test fails.
f8dbe03
Contributor

soulseekah commented Nov 10, 2012

This is the traceback:

======================================================================
ERROR: test_session_transactions_setup_request (flask.testsuite.testing.TestToolsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/www/flask/flask/testsuite/testing.py", line 120, in test_session_transactions_setup_request
    pass
  File "/usr/local/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/home/www/flask/flask/testing.py", line 92, in session_transaction
    self.cookie_jar.extract_wsgi(c.request.environ, headers)
  File "/home/www/flask/flask/ctx.py", line 288, in __exit__
    self.pop(exc_value)
  File "/home/www/flask/flask/ctx.py", line 258, in pop
    self.app.do_teardown_request(exc)
  File "/home/www/flask/flask/app.py", line 1644, in do_teardown_request
    rv = func(exc)
  File "/home/www/flask/flask/testsuite/testing.py", line 116, in teardown_request
    assert flask.g.exists
  File "/home/www/misc/env/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
    return getattr(self._get_current_object(), name)
AttributeError: '_RequestGlobals' object has no attribute 'exists'

More here: https://travis-ci.org/mitsuhiko/flask/jobs/3139261/#L328

before_request is never called, thus the missing exists attribute inside the global g object proxy.

@soulseekah soulseekah session_transaction needs preprocess_request
test_request_context() called by session_transaction() never calls
any of the before_request functions, but calls teardown_request
functions. This may result in missing objects that are created
inside the before_request functions.

The concept is fairly described in:
- http://flask.pocoo.org/docs/shell/#working-with-the-shell
- http://flask.pocoo.org/docs/testing/#other-testing-tricks

Further discussion issue #632
- #632
e79bd8f
Owner

mitsuhiko commented Dec 27, 2012

That is actually intentional. Teardown handlers always have to be written in a way that they still work if the before-request handler does not execute. Where is that behavior a problem?

Contributor

soulseekah commented Dec 27, 2012

I guess.

@soulseekah soulseekah closed this Dec 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment