Skip to content

Commit

Permalink
[#1701] Don't index empty dates as the current one
Browse files Browse the repository at this point in the history
When parsing an empty string, dateutil will always use a default one,
which by default is now(). We use here a fake date to see if that was
the case, and if so remove the value from the dict to index.
  • Loading branch information
amercader committed Aug 1, 2014
1 parent 86ec831 commit 6568761
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ckan/lib/search/index.py
Expand Up @@ -3,6 +3,7 @@
import logging
import collections
import json
import datetime
from dateutil.parser import parse

import re
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6568761

Please sign in to comment.