diff --git a/ckan/lib/search/index.py b/ckan/lib/search/index.py index 9b50031df4b..bea24535e03 100644 --- a/ckan/lib/search/index.py +++ b/ckan/lib/search/index.py @@ -3,6 +3,7 @@ import logging import collections import json +import datetime from dateutil.parser import parse import re @@ -200,11 +201,18 @@ def index_package(self, pkg_dict, defer_commit=False): # be needed? For my data not changing the keys seems to not cause a # problem. new_dict = {} + bogus_date = datetime.datetime(1, 1, 1) for key, value in pkg_dict.items(): key = key.encode('ascii', 'ignore') if key.endswith('_date'): try: - value = parse(value).isoformat() + 'Z' + date = parse(value, default=bogus_date) + if date != bogus_date: + value = date.isoformat() + 'Z' + else: + # The date field was empty, so dateutil filled it with + # the default bogus date + value = None except ValueError: continue new_dict[key] = value