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

'pyramid.request.Request object' has no attribute 'session' #891

Closed
mielvds opened this issue Jul 9, 2024 · 2 comments
Closed

'pyramid.request.Request object' has no attribute 'session' #891

mielvds opened this issue Jul 9, 2024 · 2 comments
Assignees
Milestone

Comments

@mielvds
Copy link
Contributor

mielvds commented Jul 9, 2024

After importing a bunch of skos thesauri, I see them listed on the homepage, so that's good. However, once I attempt to open one of them (e.g., http://localhost:6545/conceptschemes/2), I get a {"message": "unexpected server error"}.

My assumption was that this is caused by not adding a --conceptscheme-uri when using import_file, but this doesn't change anything.

Just as a note: import_file should look for the URIs that are instances of skos:Conceptscheme when importing, rather than assigning a new URI or asking to repeat it. This behaviour is implemented in skosprovider_rdf at https://github.com/OnroerendErfgoed/skosprovider_rdf/blob/ed8afa1cd7064b6808a34f7fa9634b4fad8741d5/skosprovider_rdf/providers.py#L58, but the URI that is extracted there, is not picked up.

This is the server logging:

2024-07-09 14:21:55 2024-07-09 12:21:55,708 INFO  [sqlalchemy.engine.Engine][waitress-3] SELECT concept_visit_log.concept_id, count(concept_visit_log.concept_id) AS count 
2024-07-09 14:21:55 FROM concept_visit_log 
2024-07-09 14:21:55 WHERE concept_visit_log.conceptscheme_id = ? AND concept_visit_log.visited_at >= ? GROUP BY concept_visit_log.concept_id ORDER BY count DESC
2024-07-09 14:21:55  LIMIT ? OFFSET ?
2024-07-09 14:21:55 2024-07-09 12:21:55,708 INFO  [sqlalchemy.engine.Engine][waitress-3] [cached since 72.21s ago] ('5', '2024-06-09', 4, 0)
2024-07-09 14:21:55 2024-07-09 12:21:55,709 ERROR [atramhasis.views.exception_views][waitress-3] 'pyramid.request.Request object' has no attribute 'session'
2024-07-09 14:21:55 Traceback (most recent call last):
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/tweens.py", line 41, in excview_tween
2024-07-09 14:21:55     response = handler(request)
2024-07-09 14:21:55                ^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/router.py", line 143, in handle_request
2024-07-09 14:21:55     response = _call_view(
2024-07-09 14:21:55                ^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/view.py", line 674, in _call_view
2024-07-09 14:21:55     response = view_callable(context, request)
2024-07-09 14:21:55                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/config/views.py", line 170, in attr_view
2024-07-09 14:21:55     return view(context, request)
2024-07-09 14:21:55            ^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/config/views.py", line 196, in predicate_wrapper
2024-07-09 14:21:55     return view(context, request)
2024-07-09 14:21:55            ^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/viewderivers.py", line 450, in rendered_view
2024-07-09 14:21:55     response = view_renderer.render_view(
2024-07-09 14:21:55                ^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/renderers.py", line 443, in render_view
2024-07-09 14:21:55     return self.render_to_response(response, system, request=request)
2024-07-09 14:21:55            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/renderers.py", line 466, in render_to_response
2024-07-09 14:21:55     result = self.render(value, system_values, request=request)
2024-07-09 14:21:55              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid/renderers.py", line 462, in render
2024-07-09 14:21:55     result = renderer(value, system_values)
2024-07-09 14:21:55              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/pyramid_jinja2/__init__.py", line 260, in __call__
2024-07-09 14:21:55     return template.render(system)
2024-07-09 14:21:55            ^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
2024-07-09 14:21:55     self.environment.handle_exception()
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
2024-07-09 14:21:55     raise rewrite_traceback_stack(source=source)
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/conceptscheme.jinja2", line 20, in top-level template code
2024-07-09 14:21:55     {% from "macros.jinja2" import
2024-07-09 14:21:55     ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/layout.jinja2", line 1, in top-level template code
2024-07-09 14:21:55     {% extends "staticlayout-page.jinja2" %}
2024-07-09 14:21:55     ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/staticlayout-page.jinja2", line 3, in top-level template code
2024-07-09 14:21:55     {% set app_name = app_name|default('Atramhasis') %}
2024-07-09 14:21:55     ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/staticlayout.jinja2", line 42, in top-level template code
2024-07-09 14:21:55     {% block subfooter %}
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/staticlayout-page.jinja2", line 23, in block 'subfooter'
2024-07-09 14:21:55     {% include 'subfooter-page.jinja2' %}
2024-07-09 14:21:55     ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/atramhasis/templates/subfooter-page.jinja2", line 14, in top-level template code
2024-07-09 14:21:55     {% for c in request.session['last_visited']|reverse() %}
2024-07-09 14:21:55     ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-09 14:21:55   File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 468, in getitem
2024-07-09 14:21:55     return obj[argument]
2024-07-09 14:21:55            ~~~^^^^^^^^^^
2024-07-09 14:21:55 jinja2.exceptions.UndefinedError: 'pyramid.request.Request object' has no attribute 'session'
2024-07-09 14:21:55 2024-07-09 12:21:55,710 INFO  [sqlalchemy.engine.Engine][waitress-3] ROLLBACK
@goessebr
Copy link
Contributor

goessebr commented Jul 19, 2024

Hi @Wim-De-Clercq,

I created a new blank scaffold from the cookiecutters. When I start my newly created application this error is raised

atramhasis_scaffold$ pserve development.ini
Traceback (most recent call last):
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/config/actions.py", line 307, in execute_actions
    callable(*args, **kw)
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/atramhasis/__init__.py", line 75, in check_session_factory_set
    raise ValueError(msg)
ValueError: No session factory is configured, and atramhasis.session_factory.secret setting is missing.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/goessebr/Envs/my_atramhasis/bin/pserve", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/scripts/pserve.py", line 30, in main
    return command.run()
           ^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/scripts/pserve.py", line 271, in run
    app = loader.get_wsgi_app(app_name, config_vars)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/plaster_pastedeploy/__init__.py", line 111, in get_wsgi_app
    return loadapp(
           ^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 246, in loadapp
    return loadobj(APP, uri, name=name, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 271, in loadobj
    return context.create()
           ^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 738, in create
    return self.object_type.invoke(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/paste/deploy/loadwsgi.py", line 136, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/paste/deploy/util.py", line 61, in fix_call
    val = callable(*args, **kw)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/dev/atramhasis_scaffold/atramhasis_scaffold/__init__.py", line 24, in main
    return config.make_wsgi_app()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/config/__init__.py", line 891, in make_wsgi_app
    self.commit()
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/config/actions.py", line 151, in commit
    self.action_state.execute_actions(introspector=self.introspector)
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/config/actions.py", line 311, in execute_actions
    reraise(
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/util.py", line 732, in reraise
    raise value.with_traceback(tb)
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/pyramid/config/actions.py", line 307, in execute_actions
    callable(*args, **kw)
  File "/home/goessebr/Envs/my_atramhasis/lib/python3.11/site-packages/atramhasis/__init__.py", line 75, in check_session_factory_set
    raise ValueError(msg)
pyramid.exceptions.ConfigurationExecutionError: <class 'ValueError'>: No session factory is configured, and atramhasis.session_factory.secret setting is missing.
  in:
  Line 0 of file None:

atramhasis.session_factory.secret is present in my development.ini, since I did not change the default config file which is provided by the cookiecutter.

Edit: I was looking in the wrong development.ini file. The atramhasis.session_factory.secret is not present in de default ini file and was indeed missing.

@goessebr
Copy link
Contributor

The session factory was missing. This error has been fixed. A default session factory is now set in case a user doesn't provide their own session factory.

@mielvds, I'm not sure what you mean by

Just as a note: import_file should look for the URIs that are instances of skos:Conceptscheme when importing, rather than assigning a new URI or asking to repeat it. This behaviour is implemented in skosprovider_rdf at https://github.com/OnroerendErfgoed/skosprovider_rdf/blob/ed8afa1cd7064b6808a34f7fa9634b4fad8741d5/skosprovider_rdf/providers.py#L58, but the URI that is extracted there, is not picked up.

I will close the issue as it has been fixed. If something else is still not correct, I would prefer a new issue.

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

No branches or pull requests

3 participants