Skip to content

Conversation

bellisk
Copy link
Contributor

@bellisk bellisk commented Jul 31, 2025

No description provided.

bellisk added 3 commits July 31, 2025 13:06
For each language in the multilang dict, we might get a string or a list of values, e.g. {'de': 'Dataset Title'} or {'de': ['tag1', 'tag2', 'tag3']}. If it's a string, we need to wrap it in a list so we can safely iterate over it in the next line - otherwise we iterate by letter: 'D', 'a', 't', ...

Checking whether the value had the '__iter__' attribute worked for this in Python 2, but in Python 3, strings apparently also have this attribute. Let's just check whether the value is a list or not. If there are any other cases, we can catch them later!
@bellisk bellisk changed the base branch from master to feat/upgrade_to_py3 July 31, 2025 11:57
# the values can be either a multilang-dict or they are
# nested in another iterable (e.g. keywords)
if not hasattr(values, "__iter__"):
if not isinstance(values, list):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently in Python 3, strings also have the __iter__ attribute. We need to really check whether the value is a list, not check for this attribute, or we won't correctly wrap a string value in a list (in the next line) and we'll end up iterating over it letter by letter.

I think there aren't any other kinds of iterable that we could get as a value here, only a list or a string, so this should be enough of a check here.

@bellisk bellisk marked this pull request as ready for review July 31, 2025 12:31
@bellisk bellisk merged commit ae17545 into feat/upgrade_to_py3 Jul 31, 2025
2 of 6 checks passed
@bellisk bellisk deleted the tests/update-tests-for-ckan-2.11-python-3 branch July 31, 2025 13:02
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 this pull request may close these issues.

2 participants