Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93ef472

Browse files
committed
Merge pull request #6056 from alphagov/fix-search-reindex-date
Catch TypeError from invalid dates thrown by dateutils
1 parent e61a91f commit 93ef472

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

ckan/lib/search/index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def index_package(self, pkg_dict, defer_commit=False):
249249
# The date field was empty, so dateutil filled it with
250250
# the default bogus date
251251
value = None
252-
except (ValueError, IndexError):
252+
except (IndexError, TypeError, ValueError):
253+
log.error('%r: %r value of %r is not a valid date', pkg_dict['id'], key, value)
253254
continue
254255
new_dict[key] = value
255256
pkg_dict = new_dict

ckan/tests/lib/search/test_index.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def test_index_date_field_wrong_value(self):
142142
"extras": [
143143
{"key": "test_wrong_date", "value": "Not a date"},
144144
{"key": "test_another_wrong_date", "value": "2014-13-01"},
145+
{"key": "test_yet_another_wrong_date", "value": "2014-15"},
146+
{"key": "test_yet_another_very_wrong_date", "value": "30/062012"},
145147
]
146148
}
147149
)
@@ -154,6 +156,8 @@ def test_index_date_field_wrong_value(self):
154156

155157
assert "test_wrong_date" not in response.docs[0]
156158
assert "test_another_wrong_date" not in response.docs[0]
159+
assert "test_yet_another_wrong_date" not in response.docs[0]
160+
assert "test_yet_another_very_wrong_date" not in response.docs[0]
157161

158162
def test_index_date_field_empty_value(self):
159163

0 commit comments

Comments
 (0)