-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Do not crash on AttributeError in dict_list_reduce helper function #2684
Conversation
value = item.get(key) | ||
except AttributeError: | ||
# item might not be a dict. | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the function is documented as taking a list of dicts, it's possibly not the right thing to do, to just silently ignore the bad data passed in. Perhaps if you raise an error that points out that it has been passed bad data (e.g. not a list of dicts) may help in tracking down the real cause of the problem (possibly in a schema somewhere?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ross Jones wrote:
As the function is documented as taking a list of dicts, it's possibly
not the right thing to do, to just silently ignore the bad data passed
in. Perhaps if you raise an error that points out that it has been
passed bad data (e.g. not a list of dicts) may help in tracking down the
real cause of the problem (possibly in a schema somewhere?).
I agree this is not the right thing to do (just did not read the
docstring :P). I can debug this live if you point me to something to
look for. The full traceback does not look very helpful from my point of
view...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that the package.resources
object passed to dict_list_reduce
is actually not a list
but a dict
(corresponding to one resource). But the package at stake actually has two resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~I think the thing to investigate is why when calling dict_list_reduce
with
h.dict_list_reduce(package.resources, 'format')
we get things that are not resource dicts. package.resources should definitely be a list of dicts.
Perhaps just dumping {{package.resources}}
in the package_item template might show what it is being passed, I can only imagine that a plugin/custom-schema is interfering somehow.~~
There's definitely some schema weirdness going on. Do you have a custom plugin? Which plugins do you use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm using ckanext-dcat and this dataset comes from a DCAT harvest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package.resources
is just one dict which looks like:
{0: {u'cache_last_updated': None,
u'issued': u'2015-10-13T15:00:17.332357',
u'uri': u'http://localhost:8080/distribution/1301',
u'package_id': u'6b0af45b-81c5-425c-bcb2-42f291937ae7',
...}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird, perhaps @amercader might know if this is a dcat extension specific weirdness.
As a temporary workaround, you can probably get away with (obviously untested)..
h.dict_list_reduce(package.resources.values(), 'format')
but it should only be a temporary workaround.
We decided to close old pull requests that are not actively worked on so that we can focus our effort and attention on PRs made against the current version of CKAN. A lot has changed in the last several months and many PRs will have gone stale or may now be in conflict with the latest version. Please note: this isn't a judgement about the quality of your pull request. We just don't have the resources to review older PRs. If you would like to reopen your PR (and update it if necessary), please do! |
I got the following error on a freshly installed CKAN 2.4.1 (source install) after adding a few datasets on a request to the home page.
Not sure why this occurs... Looking closer, I saw
0
and1
integers values asitem
(key
was'format'
).