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

Validation Errors in ckanext-usmetadata #3371

Closed
nickumia-reisys opened this issue Aug 6, 2021 · 0 comments
Closed

Validation Errors in ckanext-usmetadata #3371

nickumia-reisys opened this issue Aug 6, 2021 · 0 comments
Assignees
Labels
bug Software defect or bug CKAN Testing

Comments

@nickumia-reisys
Copy link
Contributor

During the py3 upgrade of ckanext-dcat_usmetadata, a call to usmetadata was made passing a null object into one of the regex validators. The error happened on PY2+CKAN2.8, but I don't think that this is version specific, the same behavior would happen on PY3+CKAN2.9.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

regex_candidate = <ckan.lib.navl.dictization_functions.Missing object at 0x7f980c22a8d0>

    def bureau_code_validator(regex_candidate):
        validator = re.compile(r'^\d{3}:\d{2}(\s*,\s*\d{3}:\d{2}\s*)*$')
>       if isinstance(validator.match(regex_candidate), type(re.match("", ""))):
E       TypeError: expected string or buffer

src/ckanext-usmetadata/ckanext/usmetadata/plugin/helper.py:26: TypeError

How to reproduce

This error was hit by running the tests on ckanext-dcat_usmetadata, but because of the py3 upgrade surrounding the extension, I'm not sure the tests can run in a reproducible way right now. To illustrate the issue, the following snippet was run,

$ python
Python 2.7.18 (default, Mar  8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> validator = re.compile(r'^\d{3}:\d{2}(\s*,\s*\d{3}:\d{2}\s*)*$')
>>> regex_candidate = None
>>> isinstance(validator.match(regex_candidate), type(re.match("", "")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected string or buffer
>>> regex_candidate = ""
>>> isinstance(validator.match(regex_candidate), type(re.match("", "")))
False
>>>

Expected behavior

We would expect that the extension would give a normal validation error. If the parameter was missing, it would give no error, but if the parameter is of the wrong type, it should probably fail with a 'wrong type' error.

Actual behavior

The code exited with a runtime TypeError.

Sketch

Update the validation functions in ckanext/usmetadata/plugin/helper.py to at least check that the input is a str before running the regex validators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Software defect or bug CKAN Testing
Projects
Archived in project
Development

No branches or pull requests

2 participants