I opened an issue to pyramid_debugtoolbar:
https://github.com/Pylons/pyramid_debugtoolbar/issues/261



On 15 May 2016 at 20:31, Vinicius Assef <[email protected]> wrote:

> Another update: The same application with debug toolbar 2.4.2 works fine.
>
> The problem occurs with debug toolbar 2.5, too.
>
> On 15 May 2016 at 20:23, Vinicius Assef <[email protected]> wrote:
>
>> On IRC, inklesspen reached the problem: it is with debug toolbar.
>> Disabling it, the app works nice.
>>
>> The problem occurs with pyramid 1.6.1 too.
>>
>> On 15 May 2016 at 20:05, Vinicius Assef <[email protected]> wrote:
>>
>>> Following Steve Piercy's suggestion on IRC, I just tried using code from
>>> here:
>>> https://github.com/Pylons/pyramid/tree/1.7-branch/docs/tutorials/wiki2/src/authentication
>>>
>>> The problem continues to me. Would it be some problem with the tutorial?
>>>
>>> On 15 May 2016 at 18:42, Vinicius Assef <[email protected]> wrote:
>>>
>>>> I'm following the SQLAlchemy + URL dispatch wiki tutorial [1] in
>>>> Pyramid 1.7b4 and I'm getting an error in the step "Adding Authentication"
>>>> [2].
>>>>
>>>> After making all recommended modifications in source files, I run the
>>>> application.
>>>>
>>>> I can see any wiki page created, but when I submit the login form, I
>>>> see the following message in browser:
>>>>
>>>> Internal Server Error
>>>>
>>>> The server encountered an unexpected internal server error
>>>>
>>>> (generated by waitress)
>>>>
>>>>
>>>> The traceback generated on console is as follows:
>>>>
>>>> 2016-05-15 18:13:58,519 INFO
>>>> [sqlalchemy.engine.base.Engine:646][waitress] BEGIN (implicit)
>>>> 2016-05-15 18:13:58,520 INFO
>>>> [sqlalchemy.engine.base.Engine:1097][waitress] SELECT users.id AS
>>>> users_id, users.name AS users_name, users.role AS users_role,
>>>> users.password_hash AS users_password_hash
>>>> FROM users
>>>> WHERE users.name = ?
>>>>  LIMIT ? OFFSET ?
>>>> 2016-05-15 18:13:58,520 INFO
>>>> [sqlalchemy.engine.base.Engine:1100][waitress] ('editor', 1, 0)
>>>> 2016-05-15 18:13:58,829 INFO
>>>> [sqlalchemy.engine.base.Engine:666][waitress] ROLLBACK
>>>> 2016-05-15 18:13:58,841 INFO
>>>> [sqlalchemy.engine.base.Engine:646][waitress] BEGIN (implicit)
>>>> 2016-05-15 18:13:58,842 INFO
>>>> [sqlalchemy.engine.base.Engine:1097][waitress] SELECT pages.id AS
>>>> pages_id, pages.name AS pages_name, pages.data AS pages_data,
>>>> pages.creator_id AS pages_creator_id
>>>> FROM pages
>>>> WHERE pages.name = ?
>>>>  LIMIT ? OFFSET ?
>>>> 2016-05-15 18:13:58,842 INFO
>>>> [sqlalchemy.engine.base.Engine:1100][waitress] ('FrontPage', 1, 0)
>>>> 2016-05-15 18:13:58,857 INFO
>>>> [sqlalchemy.engine.base.Engine:1097][waitress] SELECT pages.id AS
>>>> pages_id, pages.name AS pages_name, pages.data AS pages_data,
>>>> pages.creator_id AS pages_creator_id
>>>> FROM pages
>>>> WHERE pages.name = ?
>>>> 2016-05-15 18:13:58,858 INFO
>>>> [sqlalchemy.engine.base.Engine:1100][waitress] ('ViniciusPage',)
>>>> 2016-05-15 18:13:58,859 INFO
>>>> [sqlalchemy.engine.base.Engine:1097][waitress] SELECT pages.id AS
>>>> pages_id, pages.name AS pages_name, pages.data AS pages_data,
>>>> pages.creator_id AS pages_creator_id
>>>> FROM pages
>>>> WHERE pages.name = ?
>>>> 2016-05-15 18:13:58,859 INFO
>>>> [sqlalchemy.engine.base.Engine:1100][waitress] ('RosangelaPage',)
>>>> 2016-05-15 18:13:58,862 INFO
>>>> [sqlalchemy.engine.base.Engine:1097][waitress] SELECT users.id AS
>>>> users_id, users.name AS users_name, users.role AS users_role,
>>>> users.password_hash AS users_password_hash
>>>> FROM users
>>>> WHERE users.id = ?
>>>> 2016-05-15 18:13:58,862 INFO
>>>> [sqlalchemy.engine.base.Engine:1100][waitress] (1,)
>>>> 2016-05-15 18:13:58,865 INFO
>>>> [sqlalchemy.engine.base.Engine:666][waitress] ROLLBACK
>>>> 2016-05-15 18:13:58,866 ERROR [waitress:341][waitress] Exception when
>>>> serving /FrontPage
>>>> Traceback (most recent call last):
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/waitress/channel.py",
>>>> line 338, in service
>>>>     task.service()
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/waitress/task.py",
>>>> line 169, in service
>>>>     self.execute()
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/waitress/task.py",
>>>> line 399, in execute
>>>>     app_iter = self.channel.server.application(env, start_response)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid/router.py",
>>>> line 236, in __call__
>>>>     response = self.invoke_subrequest(request, use_tweens=True)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid/router.py",
>>>> line 211, in invoke_subrequest
>>>>     response = handle_request(request)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid_debugtoolbar/toolbar.py",
>>>> line 266, in toolbar_tween
>>>>     toolbar.process_response(request, response)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid_debugtoolbar/toolbar.py",
>>>> line 87, in process_response
>>>>     panel.process_response(response)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid_debugtoolbar/panels/request_vars.py",
>>>> line 112, in process_response
>>>>     extracted_attributes = extract_request_attributes(self.request)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid_debugtoolbar/panels/request_vars.py",
>>>> line 56, in extract_request_attributes
>>>>     if not hasattr(request, attr_):
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/pyramid/security.py",
>>>> line 344, in authenticated_userid
>>>>     return policy.authenticated_userid(self)
>>>>   File
>>>> "/Users/viniciusban/projects/tutoriais-pyramid/sqla/sqla/security.py", line
>>>> 11, in authenticated_userid
>>>>     return user.id
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/sqlalchemy/orm/attributes.py",
>>>> line 237, in __get__
>>>>     return self.impl.get(instance_state(instance), dict_)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/sqlalchemy/orm/attributes.py",
>>>> line 578, in get
>>>>     value = state._load_expired(state, passive)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/sqlalchemy/orm/state.py",
>>>> line 474, in _load_expired
>>>>     self.manager.deferred_scalar_loader(self, toload)
>>>>   File
>>>> "/Users/viniciusban/virtualenvs/pyramid_sqla_tut/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>>>> line 610, in load_scalar_attributes
>>>>     (state_str(state)))
>>>> sqlalchemy.orm.exc.DetachedInstanceError: Instance <User at
>>>> 0x111ac67f0> is not bound to a Session; attribute refresh operation cannot
>>>> proceed
>>>>
>>>>
>>>> According to this traceback, the error is raised at the last line of
>>>> MyAuthenticationPolicy class when I try to access request.user:
>>>>
>>>> class MyAuthenticationPolicy(AuthTktAuthenticationPolicy):
>>>>     def authenticated_userid(self, request):
>>>>         user = request.user
>>>>         if user is not None:
>>>>             return user.id
>>>>
>>>> Strange is I can access http://localhost:6543/404 by hand and see the
>>>> request.user.name showed next to the "Logout" link (coming from the
>>>> layout.jinja2 template).
>>>>
>>>> I can log out successfuly.
>>>>
>>>> Any advice?
>>>>
>>>>
>>>> For more information, I am using Python 3.5.1 in OS X El Capitan. Here
>>>> are all libs installed in my virtualenv:
>>>>
>>>> $ pip freeze
>>>> bcrypt==2.0.0
>>>> beautifulsoup4==4.4.1
>>>> cffi==1.6.0
>>>> coverage==4.0.3
>>>> docutils==0.12
>>>> Jinja2==2.8
>>>> Mako==1.0.4
>>>> MarkupSafe==0.23
>>>> PasteDeploy==1.5.2
>>>> py==1.4.31
>>>> pycparser==2.14
>>>> Pygments==2.1.3
>>>> pyramid==1.7b4
>>>> pyramid-debugtoolbar==3.0
>>>> pyramid-jinja2==2.6.2
>>>> pyramid-mako==1.0.2
>>>> pyramid-tm==0.12.1
>>>> pytest==2.9.1
>>>> pytest-cov==2.2.1
>>>> repoze.lru==0.6
>>>> six==1.10.0
>>>> sqla==0.0
>>>> SQLAlchemy==1.0.12
>>>> transaction==1.5.0
>>>> translationstring==1.3
>>>> venusian==1.0
>>>> waitress==0.9.0
>>>> WebOb==1.6.0
>>>> WebTest==2.0.21
>>>> zope.deprecation==4.1.2
>>>> zope.interface==4.1.3
>>>> zope.sqlalchemy==0.7.6
>>>>
>>>>
>>>> [1]
>>>> http://docs.pylonsproject.org/projects/pyramid/en/1.7-branch/tutorials/wiki2/index.html
>>>> [2]
>>>> http://docs.pylonsproject.org/projects/pyramid/en/1.7-branch/tutorials/wiki2/authentication.html
>>>>
>>>>
>>>> I already checked my source code and it is according to the tutorial
>>>> recommendations. What must I do to fix it?
>>>> Any help is very appreciated.
>>>>
>>>> --
>>>> Vinicius Assef
>>>>
>>>>
>>>>
>>>>
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAFmXjSBt2ati-LET756%2BiJS8PS5Nf7vZjSfwxqBAR7cz6oQX3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to