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

resource_extras.html does not support non-ascii resource names #5785

Closed
Manoj-nathwani opened this issue Dec 9, 2020 · 1 comment · Fixed by #5871
Closed

resource_extras.html does not support non-ascii resource names #5785

Manoj-nathwani opened this issue Dec 9, 2020 · 1 comment · Fixed by #5871
Assignees

Comments

@Manoj-nathwani
Copy link

CKAN version
2.9.1 - python2

Describe the bug

  • The ckan /snippets/changes/resource_extras.html was not correctly handling resource names
  • It's due to change.resource_name having non-ascii characters and then being placed within a str.format()

Steps to reproduce

  • Create a dataset called Côte d'Ivoire Inputs UNAIDS Estimates 2021
  • Upload a resource to the dataset
  • View the Activity Stream of the dataset
  • Click the Changes button under one of the items
  • You will be given a server error

Stack Trace

File "/usr/lib/ckan/venv/src/ckan/ckan/templates/snippets/changes/resource_extras.html", line 110, in top-level template code
        {{ _('Added field <q>{key}</q> with value <q>{value}</q> to resource {resource_link} in {pkg_link}').format(
          pkg_link = '<a href="{pkg_url}">{pkg_name}</a>'.format(
            pkg_url = h.url_for(controller='dataset',
                                action='read', id=change.pkg_id),
            pkg_name = change.title
          )|safe,
          resource_link = '<a href="{resource_url}">{resource_name}</a>'.format(
            resource_url = h.url_for(qualified=True, controller='resource',
                                      action='read', id=change.pkg_id,
                                      resource_id = change.resource_id),
            resource_name = change.resource_name
          )|safe,
          key = change.key,
          value = change.value
        ) }}
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 1: ordinal not in range(128)

🔴 The error is with change.resource_name being unicode and being used within a str.format()

Additional details

@Manoj-nathwani
Copy link
Author

It's worth noting this may be a problem elsewhere too.
Not exclusively in /snippets/changes/resource_extras.html

Zharktas added a commit that referenced this issue Feb 3, 2021
[#5785] Solve encoding error by simplifying changes templates
espona added a commit to EnviDat/ckan-forked that referenced this issue Feb 27, 2021
Merge commit '1b6d91790cfa668a6226f366b91dde68ae5d84b9' into 2.9

* commit '1b6d91790cfa668a6226f366b91dde68ae5d84b9': (76 commits)
  Update version number for 2.9.2
  Changelog for 2.9.2
  Coding standards
  Remove 2.9 changelog fragments
  Frontend build
  [i18n] Compile mo files
  [i18n] Update po files from transifex
  pytest-ckan support on py2/py3
  pep8
  [ckan#5670] pep8
  [ckan#5670] Add test
  [ckan#5670] Return content-type header on downloads if mimetype is present
  [ckan#5785] Solve encoding error by simplifying changes templates
  Add towncrierr fragment
  Reduce line length
  Format with black
  PEP8
  Add API Token CLI commands
  [ckan#5751] Persist attributes in chained functions
  Allow list for functions in datastore_search_sql
  ...

# Conflicts:
#	ckan/views/group.py
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.

2 participants