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

Incorrect warnings when ckan.views.default_views is (almost) empty #3093

Closed
torfsen opened this issue Jun 6, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@torfsen
Copy link
Contributor

commented Jun 6, 2016

Due to #3011 I recently set

ckan.views.default_views =

in my INI, so that by default no views are created at all.

Since then I'm getting many warnings of the form

2016-06-06 16:23:03,537 WARNI [ckan.lib.datapreview] Plugin for view  could not be found

The problem seems to be that ckan.lib.datapreview.get_default_view_plugins splits the configuration value in a rather naive way:

default_view_types = config.get('ckan.views.default_views').split(' ')

Using .split(' ') will split on a single space, thereby creating problems with leading, trailing, and multiple spaces:

>>> ' foo  bar  '.split(' ')
['', 'foo', '', 'bar', '', '']

Even worse:

>>> ''.split(' ')
['']

To simply split on whitespace (as was probably intended), use the no-argument form of split:

>>> ' foo  bar  '.split()
['foo', 'bar']
>>> ''.split()
[]

Using split() instead of split(' ') fixes the issue for me. I'll create a PR.

A quick grep turns up a few other places with similar code (although I didn't check whether they are also problematic):

$ grep -r "split(' ')" --include "*.py" ckan ckanext/
ckan/logic/action/get.py:            fq = ' '.join(p for p in fq.split(' ')
ckan/lib/helpers.py:                                   kwargs.get('action', '')).split(' ')
ckan/lib/datapreview.py:        default_view_types = config.get('ckan.views.default_views').split(' ')
ckan/ckan_nose_plugin.py:##        #    testname = testname.split(' ')[1]

$ grep -r 'split(" ")' --include "*.py" ckan ckanext/
ckan/lib/base.py:                in config['ckan.cors.origin_whitelist'].split(" "):

@amercader amercader closed this in 65b4e7d Jun 7, 2016

amercader added a commit that referenced this issue Jun 7, 2016

Merge pull request #3094 from torfsen/3093-fix-split-usage
Fix #3093: Incorrect usage of str.split

amercader added a commit that referenced this issue Aug 25, 2016

Fix #3093: Incorrect usage of `str.split`.
Conflicts:
	ckan/logic/action/get.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.