Skip to content

[Python] Fix BigTableEnrichmentHandler None row keys and KeyError text (#41346) - #41698

Open
shikhabhadoria wants to merge 2 commits into
apache:masterfrom
shikhabhadoria:fix-bigtable-enrichment-none-key-41346
Open

shikhabhadoria wants to merge 2 commits into
apache:masterfrom
shikhabhadoria:fix-bigtable-enrichment-none-key-41346

Conversation

@shikhabhadoria

Copy link
Copy Markdown
Contributor

Purpose

Fixes #41346.

BigTableEnrichmentHandler had two bugs when resolving row_key:

  1. A None join key was coerced with str(None) to None, so Bigtable was queried for literal b'None'.
  2. A missing row_key field raised KeyError with a blank name because the handler interpolated the unset row_key_str instead of self._row_key.

Changes

  • Treat None lookup values like an empty enrichment result and honor ExceptionLevel (WARN / RAISE / QUIET) without calling read_row.
  • Scope the missing-field KeyError to request_dict[self._row_key] and include self._row_key in the message (so custom row_key_fn failures are not rewritten).
  • Use %r in get_cache_key so None and the string "None" do not share a Redis cache key.

Testing

  • Reproduced both failures with a mocked table (queried b'None'; blank KeyError text).
  • Added unit tests for None keys at each ExceptionLevel, missing-field message, row_key_fn KeyError passthrough, and cache-key distinction.
  • pytest on bigtable_test.py: 8 passed
  • yapf / ruff clean

Skip Bigtable lookups when the configured row_key field is None instead
of querying bNone, report the actual field name when it is missing,
and keep None distinct from the string None in cache keys (apache#41346).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR resolves two bugs in BigTableEnrichmentHandler: preventing None lookup values from being coerced to b'None' when querying Bigtable, and fixing the missing-field KeyError message to include the configured row_key field name rather than an empty string. The implementation is well-scoped, avoids rewriting custom row_key_fn KeyErrors, prevents cache key collisions between None and 'None', and includes thorough unit test coverage.

🔍 General Feedback

  • The refactoring of empty-row handling into _handle_empty_row cleanly unifies ExceptionLevel behavior (WARN, RAISE, QUIET) between None join keys and missing Bigtable rows.
  • Replacing the import of _row_key_fn from bigtable_it_test in bigtable_test.py removes an unnecessary coupling to integration test dependencies (like testcontainers) when running unit tests.
  • Minor cleanup needed in CHANGES.md for an accidental blank line in the template comment.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

Comment thread CHANGES.md Resolved
@github-actions github-actions Bot added python core size/m M: 50-249 lines changed labels Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.
Backup reviewer: shunping (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

…ssing

Decode the key from row_key_fn for empty-row warnings and treat a None
return like a missing join key. Drop the extra blank line in the CHANGES
template.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyError

1 participant