Skip to content

fix: prevent CitationMixin crash when context missing 'context' key - #2460

Closed
truecallerabreham wants to merge 1 commit into
567-labs:mainfrom
truecallerabreham:fix/citation-mixin-none-crash
Closed

fix: prevent CitationMixin crash when context missing 'context' key#2460
truecallerabreham wants to merge 1 commit into
567-labs:mainfrom
truecallerabreham:fix/citation-mixin-none-crash

Conversation

@truecallerabreham

Copy link
Copy Markdown

Summary

Fix CitationMixin.validate_sources crash when validation_context is provided but doesn't contain the expected "context" key.

Problem

validate_sources calls info.context.get("context", None) which returns None if the key is missing. This None is passed to get_spans(None), which calls _get_span(quote, None), which calls regex.search(pattern, None) — raising TypeError: expected string or bytes-like object.

Fix

Add if text_chunks is None: return self after the .get() call (1 line).

Test

Added tests/dsl/test_citation.py with 3 regression tests covering:

  • Missing "context" key in validation_context
  • None context
  • Normal operation with valid context

Issue

Closes #2459

@ErenAta16 ErenAta16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correcting my own review on #2492: I described that as one of two PRs for #2459 when there are actually four, and this one predates all of them by eight days. My duplicate check was too shallow, apologies.

The fix here is right, and identical in substance to #2488 and #2492: info.context.get("context", None) returns None when the validation context exists but has no context key, and both downstream uses assume a string:

regex.search('(quote){e<=0}', None) -> TypeError: expected string or buffer

with text_chunks[span[0]:span[1]] failing on None right after. Returning early is the correct shape, and it matches the info.context is None guard already two lines up.

Comparing the four for whoever triages:

PR date test notes
#2460 (this) Jul 18 yes, new tests/dsl/test_citation.py earliest
#2471 Jul 20 - closed
#2488 Jul 26 yes, in existing coverage file adds CHANGELOG entry
#2492 Jul 27 no

This one has priority by date and ships a test. The only thing #2488 carries that this doesn't is the CHANGELOG line, which is trivial to add here. I'd land this one.

@jxnl

jxnl commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Closed as a duplicate implementation. The citation-context fix and regression coverage shipped in #2495 via the consolidated canonical patch.

@jxnl jxnl closed this Jul 29, 2026
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.

CitationMixin crashes when validation_context missing 'context' key

3 participants