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

Exception in the dashboard page after #7943 #7980

Closed
amercader opened this issue Dec 13, 2023 · 3 comments · Fixed by #8020
Closed

Exception in the dashboard page after #7943 #7980

amercader opened this issue Dec 13, 2023 · 3 comments · Fixed by #8020
Assignees

Comments

@amercader
Copy link
Member

CKAN version

master

Describe the bug

Exception when visiting the /dashboard page

  File "/home/adria/dev/pyenvs/ckan-py3.9/ckan/ckanext/activity/templates/snippets/activities/new_organization.html", line 9, in top-level template code
    )|safe }}
  File "/home/adria/.pyenv/versions/3.9.16/envs/ckan-py3.9/lib/python3.9/site-packages/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
  File "/home/adria/dev/pyenvs/ckan-py3.9/ckan/ckanext/activity/templates/snippets/stream.html", line 17, in template
    <a href="{{ h.url_for(group_type ~ '.read', id=activity.object_id) }}">
  File "/home/adria/dev/pyenvs/ckan-py3.9/ckan/ckan/lib/helpers.py", line 381, in url_for
    my_url = _url_for_flask(*args, **kw)
  File "/home/adria/dev/pyenvs/ckan-py3.9/ckan/ckan/lib/helpers.py", line 439, in _url_for_flask
    my_url = _flask_default_url_for(*args, **kw)
  File "/home/adria/.pyenv/versions/3.9.16/envs/ckan-py3.9/lib/python3.9/site-packages/flask/helpers.py", line 225, in url_for
    return current_app.url_for(
  File "/home/adria/.pyenv/versions/3.9.16/envs/ckan-py3.9/lib/python3.9/site-packages/flask/app.py", line 1697, in url_for
    return self.handle_url_build_error(error, endpoint, values)
  File "/home/adria/.pyenv/versions/3.9.16/envs/ckan-py3.9/lib/python3.9/site-packages/flask/app.py", line 1686, in url_for
    rv = url_adapter.build(  # type: ignore[union-attr]
  File "/home/adria/.pyenv/versions/3.9.16/envs/ckan-py3.9/lib/python3.9/site-packages/werkzeug/routing/map.py", line 950, in build
    raise BuildError(endpoint, values, method, self)
werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'activity.read' with values ['id']. Did you mean 'dataset.read' instead?

Steps to reproduce

  • Activate the activity plugin
  • Create an organization
  • Visit the /dashboard page (News items)

Expected behavior

No exception

Additional details

This was introduced in #7943 . The changes there didn't take into account the scenario where group_type is empty (because the stream.html snippet is called from the dashboard, and not from the organization activity page). The fix below should address the issue, but a patch should also include:

  • A test that covers the issue
  • Extend the support for group_type to the {% macro group(activity) %} block in the same template.
diff --git a/ckanext/activity/templates/snippets/stream.html b/ckanext/activity/templates/snippets/stream.html
index 52c0d4b49..ddd6f9d05 100644
--- a/ckanext/activity/templates/snippets/stream.html
+++ b/ckanext/activity/templates/snippets/stream.html
@@ -14,6 +14,7 @@
 {% endmacro %}
 
 {% macro organization(activity) %}
+  {% set group_type = group_type or 'organization' %}
   <a href="{{ h.url_for(group_type ~ '.read', id=activity.object_id) }}">
     {{ activity.data.group.title if activity.data.group else _('unknown') }}
   </a>
@tgurr
Copy link

tgurr commented Jan 15, 2024

Just adding since in the initial report ckan version from master is mentioned, I'm also hitting this issue with 2.10.3 (after upgrading from 2.10.1 - however I did not have the activity plugin enabled previously, just noticed it when generating a new config for the beaker stuff and diffing with my old, updating mine accordingly)

@ThrawnCA
Copy link
Contributor

I was lucky to catch this error; we're updating our DEV sites to 2.10.3, and my initial testing didn't see any problems, because the account I was using hadn't recently added/changed any organisations. Fortunately when I tested on another site, I happened to use an account that was affected.

If custom org types are to be supported, then should we be actually passing in a group_type from the user activity page, instead of falling back to organization?

@ThrawnCA
Copy link
Contributor

It looks like the group is already accessible via the activity object, so instead of just falling back to organization we can use:

{% set group_type = group_type or (activity.data.group.type if (activity.data.group and activity.data.group.type) else 'organization') %}

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.

4 participants