Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Did #46 break subrequests ? #47

Closed
olemoign opened this issue Oct 21, 2016 · 3 comments · Fixed by #48
Closed

Did #46 break subrequests ? #47

olemoign opened this issue Oct 21, 2016 · 3 comments · Fixed by #48

Comments

@olemoign
Copy link
Contributor

I just updated pyramid_tm (0.12.1 => 1.0) in my app and the endpoint that uses subrequests now returns

Error
Traceback (most recent call last):
  File "/Users/olemoign/Developer/KmForChange/kmforchange-ws/kmforchange/tests/test_users.py", line 96, in test_user_settings_without_password
    res = self.app.put_json('/api/settings', params=json, status=200)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webtest/utils.py", line 36, in wrapper
    return self._gen_request(method, url, **kw)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webtest/app.py", line 740, in _gen_request
    expect_errors=expect_errors)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webtest/app.py", line 610, in do_request
    res = req.get_response(app, catch_exc_info=True)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webob/request.py", line 1295, in send
    application, catch_exc_info=True)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webob/request.py", line 1263, in call_application
    app_iter = application(self.environ, start_response)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/webtest/lint.py", line 198, in lint_app
    iterator = application(environ, start_response_wrapper)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/router.py", line 236, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/router.py", line 211, in invoke_subrequest
    response = handle_request(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/tweens.py", line 51, in excview_tween
    request_iface=request_iface.combined
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 413, in viewresult_to_response
    result = view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 109, in tm_tween
    reraise(*exc_info)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 88, in tm_tween
    response = handler(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/router.py", line 158, in handle_request
    view_name
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 302, in _secured_view
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
    result = view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/cornice/service.py", line 571, in wrapper
    response = view_()
  File "/Users/olemoign/Developer/KmForChange/kmforchange-ws/kmforchange/services.py", line 403, in put
    self.request.invoke_subrequest(sub_request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/router.py", line 211, in invoke_subrequest
    response = handle_request(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/router.py", line 158, in handle_request
    view_name
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 300, in _secured_view
    result = _permitted(context, request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/viewderivers.py", line 291, in _permitted
    principals = authn_policy.effective_principals(request)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/authentication.py", line 157, in effective_principals
    groups = self.callback(userid, request)
  File "/Users/olemoign/Developer/KmForChange/kmforchange-ws/kmforchange/__init__.py", line 33, in get_effective_principals
    if request.user and request.user.email_confirmed:
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/decorator.py", line 42, in __get__
    val = self.wrapped(inst)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/util.py", line 67, in <lambda>
    fn = lambda this: callable(this)
  File "/Users/olemoign/Developer/KmForChange/kmforchange-ws/kmforchange/__init__.py", line 29, in get_user
    return request.db_session.query(User).get(userid)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/decorator.py", line 42, in __get__
    val = self.wrapped(inst)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/util.py", line 67, in <lambda>
    fn = lambda this: callable(this)
  File "/Users/olemoign/Developer/KmForChange/kmforchange-ws/kmforchange/models/__init__.py", line 75, in <lambda>
    lambda r: get_tm_session(session_factory, r.tm),
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/decorator.py", line 42, in __get__
    val = self.wrapped(inst)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid/util.py", line 67, in <lambda>
    fn = lambda this: callable(this)
  File "/Users/olemoign/.pyenv/versions/kmforchange-ws/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 118, in create_tm
    raise AttributeError('tm inactive for request or accessed above tm '
AttributeError: tm inactive for request or accessed above tm tween

Reference code:

from pyramid.request import Request

sub_request = Request.blank(self.request.route_url('companysignup'))
sub_request.method = 'POST'
sub_request.cookies = self.request.cookies
sub_request.body = dumps({'email': self.request.json_body['login']}).encode('ascii')
self.request.invoke_subrequest(sub_request)

This looks very much to me that the MR #46 breaks subrequests ...

@tseaver
Copy link
Member

tseaver commented Oct 21, 2016

@olemoign Thanks for the report! @mmerickel can you help diagnose?

@mmerickel
Copy link
Member

Yes, this also broke uses of the tm inside pshell and other pyramid.paster.bootstrap related shell scripts. I've been pondering for a couple weeks whether to just revert the change and I think it's the best option.

@mmerickel
Copy link
Member

I released 1.0.1 which fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants