ckanext-pages icon indicating copy to clipboard operation
ckanext-pages copied to clipboard

2.11 ckanext.pages.organization=true crashes activity tab

Open brooks-eco opened this issue 1 year ago • 2 comments

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

brooks-eco avatar Sep 21 '24 13:09 brooks-eco

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: https://github.com/mjanez/ckanext-pages/commit/7c121ca3abdb16e291ad81fadf53b70b4176bc28

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.

mjanez avatar Nov 13 '24 09:11 mjanez

I confirm this fix made it ! Thanks

BENETNATH avatar Nov 25 '24 13:11 BENETNATH