Skip to content

fix(query_analyzer): handle dateparser internal crashes gracefully - #893

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/query-analyzer-dateparser-crash
Apr 7, 2026
Merged

fix(query_analyzer): handle dateparser internal crashes gracefully#893
nicoloboschi merged 1 commit into
mainfrom
fix/query-analyzer-dateparser-crash

Conversation

@cdbartholomew

Copy link
Copy Markdown
Contributor

Summary

DateparserQueryAnalyzer.analyze() calls dateparser.search.search_dates() without any error handling. The third-party library has been observed to crash with internal errors on certain query inputs, propagating the exception all the way up the search/consolidation pipeline and failing the calling task.

Observed traceback

File ".../engine/query_analyzer.py", line 140, in analyze
    results = self._search_dates(query, settings=settings)
File ".../dateparser/search/search.py", line 294, in search_dates
    "Dates": self.search.search_parse(...)
File ".../dateparser/search/search.py", line 168, in search_parse
    translated, original = self.search(shortname, text, settings)
File ".../dateparser/languages/locale.py", line 224, in translate_search
    [original_tokens[i], original_tokens[i + 1]],
IndexError: list index out of range

This has been observed repeatedly on the same bank, suggesting at least one stored memory contains text that reliably triggers the dateparser bug. Each consolidation cycle re-runs the same query and crashes the same way.

Fix

Wrap the _search_dates call in a try/except so any parser failure is treated as "no temporal constraint found" — the caller falls back to non-temporal retrieval instead of erroring out the whole task. The failure is logged at WARNING level so it's still visible.

Test plan

  • Added a regression test that monkey-patches _search_dates to raise an IndexError, asserts the analyzer returns an empty constraint, and asserts a warning is logged.
  • Ran the full test_query_analyzer.py suite — 16 passed.
  • CI passes

DateparserQueryAnalyzer.analyze() called dateparser.search.search_dates()
without any error handling, so internal bugs in the third-party library
propagated all the way up the search/consolidation pipeline and failed
the calling task.

Observed traceback:

  File ".../engine/query_analyzer.py", line 140, in analyze
    results = self._search_dates(query, settings=settings)
  File ".../dateparser/search/search.py", line 294, in search_dates
    "Dates": self.search.search_parse(...)
  File ".../dateparser/search/search.py", line 168, in search_parse
    translated, original = self.search(shortname, text, settings)
  File ".../dateparser/languages/locale.py", line 224, in translate_search
    [original_tokens[i], original_tokens[i + 1]],
  IndexError: list index out of range

Wrap the call in a try/except so any parser failure is treated as
"no temporal constraint found" — the caller can then fall back to
non-temporal retrieval instead of erroring out the whole task. The
failure is logged at WARNING level so we still notice it.

Add a regression test that monkey-patches _search_dates to raise an
IndexError and asserts the analyzer returns an empty constraint and
emits a warning log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants