Skip to content

Commit

Permalink
Merge pull request #35025 from dimagi/mjr/disable-sentry-dedupe-error
Browse files Browse the repository at this point in the history
Ignore failing dedupe records with long stale ES data
  • Loading branch information
mjriley authored Aug 23, 2024
2 parents 71afaf9 + e7cceca commit 89a3684
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 7 additions & 1 deletion corehq/apps/data_interfaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,13 @@ def _handle_case_duplicate(self, case, rule):
# We've decided skipping this record and recording an error is likely the safest way to handle this
# Hopefully, these errors allow us to track down the underlying bug or infrastructure issue
# and fix the issue at the source
raise ValueError(f'Unable to find current ElasticSearch data for: {case.case_id}')

# TODO: Commenting this line out, as it has caused us to surpass our sentry error quota
# we should figure out whether this can be safely handled, or what truly constitutes an error,
# but disabling this to avoid further quota issues.
# raise ValueError(f'Unable to find current ElasticSearch data for: {case.case_id}')
# Ignore this result for now
return CaseRuleActionResult(num_errors=1)
else:
# Normal processing can involve latency between when a case is written to the database and when
# it arrives in ElasticSearch. If this case was modified within the acceptable latency window,
Expand Down
9 changes: 4 additions & 5 deletions corehq/apps/data_interfaces/tests/test_case_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,15 @@ def test_ignores_recent_submissions_not_in_elasticsearch(self, mock_case_exists,
self.assertEqual(created_duplicates.count(), 0)

@patch("corehq.apps.data_interfaces.models.case_matching_rule_criteria_exists_in_es")
def test_raises_error_when_case_not_in_elasticsearch(self, mock_case_exists):
def test_returns_error_result_when_case_not_in_elasticsearch(self, mock_case_exists):
current_time = datetime(year=2024, month=2, day=5, hour=10)
case = self._create_case()
case.server_modified_on = current_time - timedelta(hours=1, seconds=1)
mock_case_exists.return_value = False

with self.assertRaisesRegex(
ValueError, f'Unable to find current ElasticSearch data for: {case.case_id}'):
with freeze_time(current_time):
self.rule.run_rule(case, datetime.now())
result = self.rule.run_rule(case, datetime.now())
self.assertEqual(result.num_updates, 0)
self.assertEqual(result.num_errors, 1)

@patch("corehq.apps.data_interfaces.models._find_duplicate_case_ids")
def test_case_no_longer_duplicate(self, find_duplicates_mock):
Expand Down

0 comments on commit 89a3684

Please sign in to comment.