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

2.11 ckanext.pages.organization=true crashes activity tab #136

Open
brooks-eco opened this issue Sep 21, 2024 · 2 comments
Open

2.11 ckanext.pages.organization=true crashes activity tab #136

brooks-eco opened this issue Sep 21, 2024 · 2 comments

Comments

@brooks-eco
Copy link

brooks-eco commented Sep 21, 2024

ckan 2.11
pages install pip install -e 'git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages
ckan db upgrade -p pages completed

with ckanext.pages.organization = True
using activity plugin, the activity tab crashes - Error in Log file

ERROR [ckan.config.middleware.flask_app] 'werkzeug.local.LocalProxy object' has no attribute 'group_dict'

to reproduce

  1. set option ckanext.pages.organization = True
  2. recycle server
  3. open organization ( new "pages tab" visible)
  4. click on "Activity" tab (/en/organization/activity/orgname?offset=0)
  5. page error during rendering (see screenshot)
  6. setting ckanext.pages.organization = False
  7. recycle server - Activity tab for organization is working again

Error log

2024-09-21 13:09:01,676 ERROR [ckan.config.middleware.flask_app] 'werkzeug.local.LocalProxy object' has no attribute 'group_dict'
Traceback (most recent call last):
File "/usr/lib/ckan/default/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/ckan/default/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/views.py", line 576, in group_activity
return tk.render(
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/lib/base.py", line 104, in render
return flask_render_template(template_name, **extra_vars)
File "/usr/lib/ckan/default/lib/python3.10/site-packages/flask/templating.py", line 150, in render_template
return _render(app, template, context)
File "/usr/lib/ckan/default/lib/python3.10/site-packages/flask/templating.py", line 131, in _render
rv = template.render(context)
File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/templates/organization/activity_stream.html", line 1, in top-level template code
{% extends "organization/read_base.html" %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/templates/organization/read_base.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/src/ckanext-pages/ckanext/pages/theme/templates_organization/organization/read_base.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/organization/read_base.html", line 3, in top-level template code
{% set organization = group_dict %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/templates/page.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/tracking/templates/page.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/charts/templates/page.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 1, in top-level template code
{% extends "base.html" %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/templates/base.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/src/ckanext-scheming/ckanext/scheming/templates/base.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/geoview/plugin/../templates/base.html", line 1, in top-level template code
{% ckan_extends %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/base.html", line 107, in top-level template code
{%- block page %}{% endblock -%}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 19, in block 'page'
{%- block content %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 22, in block 'content'
{% block main_content %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 74, in block 'main_content'
{% block primary %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 87, in block 'primary'
{% block primary_content %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 89, in block 'primary_content'
{% block page_header %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckan/templates/page.html", line 97, in block 'page_header'
{% block content_primary_nav %}{% endblock %}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/ckanext/activity/templates/organization/read_base.html", line 4, in block 'content_primary_nav'
{{ super() }}
File "/usr/lib/ckan/default/src/ckanext-pages/ckanext/pages/theme/templates_organization/organization/read_base.html", line 6, in block 'content_primary_nav'
{{ h.build_nav_icon('pages.organization_pages_index', _('Pages'), id=c.group_dict.name, icon='file') }}
File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/environment.py", line 487, in getattr
return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'werkzeug.local.LocalProxy object' has no attribute 'group_dict'

Screen shot - page crashed during render
(site logo is mostly white text with transparent background - explains the odd symbol on the left)

image

@mjanez
Copy link

mjanez commented Nov 13, 2024

This error occurs because, in newer versions of CKAN, group_dict (and other context objects like organization_dict) are not always accessible through the global c object, as they were in previous versions. This creates a compatibility issue for ckanext-pages in CKAN 2.11 when it attempts to access c.group_dict.

Can check fork: mjanez@7c121ca

Solution: Apply the Patch

The fix is to update the templates to use group_dict directly instead of c.group_dict. Here’s the complete patch to apply:

diff --git a/ckanext/pages/theme/templates_group/group/read_base.html b/ckanext/pages/theme/templates_group/group/read_base.html
index bbdae8f..6bf00fa 100644
--- a/ckanext/pages/theme/templates_group/group/read_base.html
+++ b/ckanext/pages/theme/templates_group/group/read_base.html
@@ -3,8 +3,8 @@
 {% block content_primary_nav %}
   {{ super() }}
   {% if h.ckan_version().split('.')[1] | int >= 9 %}
-    {{ h.build_nav_icon('pages.group_pages_index', _('Pages'), id=c.group_dict.name, icon='file') }}
+    {{ h.build_nav_icon('pages.group_pages_index', _('Pages'), id=group_dict.name, icon='file') }}
   {% else %}
-    {{ h.build_nav_icon('group_pages_index', _('Pages'), id=c.group_dict.name, icon='file') }}
+    {{ h.build_nav_icon('group_pages_index', _('Pages'), id=group_dict.name, icon='file') }}
   {% endif %}
 {% endblock %}
diff --git a/ckanext/pages/theme/templates_main/ckanext_pages/confirm_delete.html b/ckanext/pages/theme/templates_main/ckanext_pages/confirm_delete.html
index 6ab5f92..c00e1d6 100644
--- a/ckanext/pages/theme/templates_main/ckanext_pages/confirm_delete.html
+++ b/ckanext/pages/theme/templates_main/ckanext_pages/confirm_delete.html
@@ -10,7 +10,7 @@
       {% block form %}
       <p>{{ _('Are you sure you want to delete page - {name}?').format(name=c.page_dict.name) }}</p>
       <p class="form-actions">
-      {% set action = form_action or h.url_for('organization_pages_delete', id=c.group_dict.name, page='/' + page) %}
+      {% set action = form_action or h.url_for('organization_pages_delete', id=group_dict.name, page='/' + page) %}
       <form action="{{ action }}" method="post">
         <button class="btn" type="submit" name="cancel" >{{ _('Cancel') }}</button>
         <button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Delete') }}</button>
diff --git a/ckanext/pages/theme/templates_organization/organization/read_base.html b/ckanext/pages/theme/templates_organization/organization/read_base.html
index e5f3b47..eb2f39b 100644
--- a/ckanext/pages/theme/templates_organization/organization/read_base.html
+++ b/ckanext/pages/theme/templates_organization/organization/read_base.html
@@ -3,8 +3,8 @@
 {% block content_primary_nav %}
   {{ super() }}
   {% if h.ckan_version().split('.')[1] | int >= 9 %}
-    {{ h.build_nav_icon('pages.organization_pages_index', _('Pages'), id=c.group_dict.name, icon='file') }}
+    {{ h.build_nav_icon('pages.organization_pages_index', _('Pages'), id=group_dict.name, icon='file') }}
   {% else %}
-    {{ h.build_nav_icon('organization_pages_index', _('Pages'), id=c.group_dict.name, icon='file') }}
+    {{ h.build_nav_icon('organization_pages_index', _('Pages'), id=group_dict.name, icon='file') }}
   {% endif %}
 {% endblock %}

Steps to Apply the Patch

  1. Locate the Files:

    • Open ckanext/pages/theme/templates_group/group/read_base.html.
    • Open ckanext/pages/theme/templates_organization/organization/read_base.html.
    • Open ckanext/pages/theme/templates_main/ckanext_pages/confirm_delete.html
  2. Edit the Files:

    • Make the changes indicated in the patch by replacing references to c.group_dict.name with group_dict.name.
  3. Restart CKAN:

    • After making these changes, restart the CKAN server for the updates to take effect.

Expected Outcome

With this patch applied, ckanext-pages should now work properly when viewing the organization’s "Activity" tab with ckanext.pages.organization=True. This resolves the 'werkzeug.local.LocalProxy object' has no attribute 'group_dict' error.

@BENETNATH
Copy link

I confirm this fix made it !
Thanks

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

No branches or pull requests

3 participants