Skip to content

[Python/YAML] Add File enrichment handler and error_handling (#41356) - #41453

Open
shikhabhadoria wants to merge 7 commits into
apache:masterfrom
shikhabhadoria:feat-yaml-enrichment-error-handling-41356
Open

shikhabhadoria wants to merge 7 commits into
apache:masterfrom
shikhabhadoria:feat-yaml-enrichment-error-handling-41356

Conversation

@shikhabhadoria

@shikhabhadoria shikhabhadoria commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #41356. Part 3 of the YAML wiring for Enrichment.

Summary

Test plan

  • Merged latest master (per @derrickaw)
  • ruff check / yapf on the YAML files
  • Python precommit after this push

Checklist

  • If this contribution is large, please file an Apache Individual Contributor License Agreement.
  • Mention the appropriate issue in the description (addresses #41356).
  • Update CHANGES.md with noteworthy changes.

@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 is the third in a three-part series (#41451, #41452, #41453) adding File enrichment handler support, on_miss, prefix, and error_handling dead-letter output to Beam YAML's Enrichment transform. The YAML integration and test coverage are well-structured, though there are a few issues in CHANGES.md placement, test helper signature compatibility, and underlying file handler/join error handling included in this branch.

🔍 General Feedback

  • Note that this branch is stacked on #41451 and #41452 against master, so the diff includes commits from all three PRs.
  • The CHANGES.md entries were accidentally inserted into the commented-out <!-- Template --> block at the top of the file rather than under the active # [2.79.0] - Unreleased section.

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

💬 Inline Findings

  • CHANGES.md (line 31): 🟡 Medium: These release notes were added inside the commented-out <!-- Template --> section (lines 19–77) instead of under the active # [2.79.0] - Unreleased ## I/Os section around line 88.

  • sdks/python/apache_beam/yaml/yaml_enrichment_test.py (line 50): 🟡 Medium: FakeEnrichmentTransform.__call__ is used to mock enrichment_transform, which now accepts on_miss and prefix parameters. Because @maybe_with_exception_handling inspects the wrapped callable's signature and yaml_provider binds defaults, FakeEnrichmentTransform.__call__ should accept on_miss='null' and prefix=None (or **kwargs) to stay consistent with enrichment_transform's updated signature.

  def __call__(self, enrichment_handler, *, handler_config, timeout=30, on_miss='null', prefix=None):
  • sdks/python/apache_beam/transforms/enrichment_handlers/file.py (line 71): 🟠 High: _load_parquet, _load_csv, and _load_json insert records[None] = projected whenever a reference row has a null or empty join_key. Returning self.records.get(None) when the input row's lookup key is None causes null foreign keys in the input PCollection to falsely match those null-keyed reference rows instead of being treated as lookup misses. A None lookup key should always be a miss.
      return None
  • sdks/python/apache_beam/transforms/enrichment_handlers/file.py (line 468): 🟠 High: _peek_schema() ignores field nullability on the Arrow schema (arrow_schema.field(c).nullable) and always returns non-Optional types for Parquet columns. Because get_output_schema() caches _peek_schema() during pipeline construction, using Enrichment(handler, on_miss='drop') (or 'fail'/'dlq') on a Parquet reference file with nullable columns sets a non-nullable RowTypeConstraint on the output PCollection, which fails when encoding None values at runtime.

  • sdks/python/apache_beam/transforms/enrichment.py (line 176): 🟡 Medium: In _EnrichmentJoinFn.process, the on_miss == 'null' branch invokes self._join_fn(...) outside the try ... except Exception as exn: block below (lines 179–200). If a custom join_fn raises an exception when handling a miss with on_miss='null' and with_exception_handling(...) (or YAML error_handling) is enabled, the exception will fail the pipeline instead of being routed to self._dead_letter_tag.

…ing (apache#41356)

Register the File enrichment handler in Beam YAML and send on_miss=dlq
rows and caller failures to the standard error_handling output.
@shikhabhadoria

Copy link
Copy Markdown
Contributor Author

Rebased this onto current master so the diff is only the Beam YAML wiring. The earlier version also contained the #41451 and #41452 commits, which is why the line count matched the original PR. Merge after those two. The new tests need both APIs, so they fail on master alone; with all three branches together, 30 tests passed.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @derrickaw for label yaml.
Backup reviewer: chamikaramj (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).

@derrickaw

Copy link
Copy Markdown
Collaborator

/gemini review

@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 cleanly wires FileEnrichmentHandler, on_miss, prefix, and error_handling into the Beam YAML Enrichment transform as part 3 of #41356. The implementation and test suite are well-structured and cover Parquet, CSV, on_miss modes, and RPC timeout routing to dead-letter outputs.

🔍 General Feedback

  • Separating the Enrichment/FileEnrichmentHandler import block from the GCP-specific handlers is a good improvement so local file enrichment only depends on core Enrichment (RequestResponseIO) rather than GCP client libraries.
  • Remember to merge #41451 and #41452 first and rebase this branch before merging so CI passes against master.

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

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions Bot added size/m M: 50-249 lines changed and removed io core size/xl XL: >=1000 lines changed labels Nov 18, 2026
@derrickaw

Copy link
Copy Markdown
Collaborator

/summarize-failures

…apache#41356)

Drop the unused json import flagged in review. Import FileEnrichmentHandler
separately so a missing module does not disable Enrichment, and skip the
file-handler tests until apache#41451 and apache#41452 are available.
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.47826% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.99%. Comparing base (5341c0f) to head (6c9e142).
⚠️ Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/yaml/yaml_enrichment.py 43.47% 13 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41453      +/-   ##
============================================
- Coverage     57.99%   57.99%   -0.01%     
  Complexity     2831     2831              
============================================
  Files          1209     1209              
  Lines        173011   173032      +21     
  Branches       2320     2320              
============================================
+ Hits         100334   100344      +10     
- Misses        69968    69979      +11     
  Partials       2709     2709              
Flag Coverage Δ
python 80.63% <43.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@derrickaw

Copy link
Copy Markdown
Collaborator

Hi @shikhabhadoria, can you fix the lint issue? Thanks

…pache#41356)

Pass on_miss and prefix only when Enrichment.__init__ accepts them so
PythonLint type checking against master Enrichment stays green.
@shikhabhadoria

Copy link
Copy Markdown
Contributor Author

@derrickaw Fixed. PythonLint was failing pyrefly because this branch calls Enrichment(..., on_miss=..., prefix=...) while master Enrichment.__init__ does not accept those kwargs yet (they land in #41451).

yaml_enrichment.py now passes on_miss and prefix only when Enrichment.__init__ accepts them, and raises a clear error if YAML asks for those options before that API is available. Local ruff check is clean and yaml_enrichment_test.py is 2 passed, 3 skipped (the file handler tests still wait on #41451 and #41452).

@shikhabhadoria

Copy link
Copy Markdown
Contributor Author

The Python 3.14 precommit failure is not from this PR. yaml_enrichment_test passed (2 passed, 3 skipped waiting on #41451/#41452). The failing test is unrelated:

apache_beam/cli/main_test.py::PipeTest::test_backslash_sequences_in_paths

It asserts Wrote 1 file: while Prism wrote 2 shards (Wrote 2 files:). Python 3.11 precommit and the macOS/Windows unit tests are green. I re-ran the failed 3.14 job.

@shikhabhadoria

Copy link
Copy Markdown
Contributor Author

Correction: gh run rerun could not re-run that workflow (cannot be rerun; its workflow file may be broken), so I pushed an empty commit to retrigger CI.

Again, the prior 3.14 failure was unrelated to this PR: PipeTest.test_backslash_sequences_in_paths expected one shard and Prism wrote two. This PR's enrichment tests were green.

@derrickaw

Copy link
Copy Markdown
Collaborator

Hi @shikhabhadoria, can you git pull merge, I believe a recent PR for bigtable went in after your last pull and may resolve the Precommit failure we see currently. Thanks

Refresh the branch onto latest master per review. Update skip/error
messages so on_miss/prefix point at the follow-up to apache#41451, while
error_handling continues to use with_exception_handling from that PR.
@shikhabhadoria

Copy link
Copy Markdown
Contributor Author

@derrickaw merged latest master into this branch and pushed. That should pick up the Bigtable precommit fix you mentioned and retrigger CI.

Also refreshed the dependency notes: YAML error_handling relies on with_exception_handling from #41451, while on_miss / prefix still wait on the follow-up to that PR (plus #41452 for the File handler). Lint/format are clean on the YAML files.

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.

2 participants