diff --git a/corehq/apps/case_search/tests/test_filter_dsl.py b/corehq/apps/case_search/tests/test_filter_dsl.py index 5f1ecaedc0e8..99fc54566dac 100644 --- a/corehq/apps/case_search/tests/test_filter_dsl.py +++ b/corehq/apps/case_search/tests/test_filter_dsl.py @@ -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')) diff --git a/corehq/apps/case_search/xpath_functions/comparison.py b/corehq/apps/case_search/xpath_functions/comparison.py index a5edcc57fb9c..59c3fb69a89a 100644 --- a/corehq/apps/case_search/xpath_functions/comparison.py +++ b/corehq/apps/case_search/xpath_functions/comparison.py @@ -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)