Skip to content

Commit

Permalink
Merge pull request #35467 from dimagi/es/system-datetime-eq
Browse files Browse the repository at this point in the history
Don't fail on system prop datetime eq matches
  • Loading branch information
esoergel authored Dec 3, 2024
2 parents 23682ba + dee048b commit 8bbee13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions corehq/apps/case_search/tests/test_filter_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ def test_datetime_system_property_filter_optimized(self, mock_get_timezone):

@freeze_time('2023-05-16T13:01:51Z')
@flag_enabled('CASE_SEARCH_INDEXED_METADATA')
@patch("corehq.apps.case_search.xpath_functions.comparison.get_timezone_for_domain",
return_value=pytz.timezone('America/Los_Angeles'))
def test_system_date_property_comparison(self, mock_get_timezone):
def test_system_datetime_property_comparison(self):
parsed = parse_xpath("last_modified < datetime-add(now(), 'weeks', -2)")
expected_filter = filters.date_range('modified_on', lt='2023-05-02T13:01:51+00:00')
built_filter = build_filter_from_ast(parsed, SearchFilterContext("domain"))
self.checkQuery(built_filter, expected_filter, is_raw_query=True)

@freeze_time('2023-05-16T13:01:51Z')
@flag_enabled('CASE_SEARCH_INDEXED_METADATA')
def test_system_datetime_property_match(self):
parsed = parse_xpath("last_modified = now()")
expected_filter = filters.term('modified_on', '2023-05-16T13:01:51+00:00')
built_filter = build_filter_from_ast(parsed, SearchFilterContext("domain"))
self.checkQuery(built_filter, expected_filter, is_raw_query=True)

def test_not_filter(self):
parsed = parse_xpath("not(name = 'farid')")
expected_filter = filters.NOT(case_property_query('name', 'farid'))
Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/case_search/xpath_functions/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _create_system_datetime_query(domain, meta_property, op, value, node):
raise CaseFilterError(str(e), serialize(node))

if isinstance(date_or_datetime, datetime):
if op == EQ:
return filters.term(meta_property.es_field_name, value)
range_kwargs = {RANGE_OP_MAPPING[op]: date_or_datetime}
else:
timezone = get_timezone_for_domain(domain)
Expand Down

0 comments on commit 8bbee13

Please sign in to comment.