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

Catch TypeError from invalid dates thrown by dateutils #6056

Merged
merged 2 commits into from May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ckan/lib/search/index.py
Expand Up @@ -249,7 +249,8 @@ def index_package(self, pkg_dict, defer_commit=False):
# The date field was empty, so dateutil filled it with
# the default bogus date
value = None
except (ValueError, IndexError):
except (IndexError, TypeError, ValueError):
log.error('%r: %r value of %r is not a valid date', pkg_dict['id'], key, value)
continue
new_dict[key] = value
pkg_dict = new_dict
Expand Down
4 changes: 4 additions & 0 deletions ckan/tests/lib/search/test_index.py
Expand Up @@ -142,6 +142,8 @@ def test_index_date_field_wrong_value(self):
"extras": [
{"key": "test_wrong_date", "value": "Not a date"},
{"key": "test_another_wrong_date", "value": "2014-13-01"},
{"key": "test_yet_another_wrong_date", "value": "2014-15"},
{"key": "test_yet_another_very_wrong_date", "value": "30/062012"},
]
}
)
Expand All @@ -154,6 +156,8 @@ def test_index_date_field_wrong_value(self):

assert "test_wrong_date" not in response.docs[0]
assert "test_another_wrong_date" not in response.docs[0]
assert "test_yet_another_wrong_date" not in response.docs[0]
assert "test_yet_another_very_wrong_date" not in response.docs[0]

def test_index_date_field_empty_value(self):

Expand Down