Skip to content

Commit

Permalink
Merge pull request #6056 from alphagov/fix-search-reindex-date
Browse files Browse the repository at this point in the history
Catch TypeError from invalid dates thrown by dateutils
  • Loading branch information
Zharktas committed May 12, 2021
1 parent e61a91f commit 93ef472
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 93ef472

Please sign in to comment.