Repository navigation
[YAML] Fix flaky ErrorHandlingTest: don't pickle Scope into user DoFn closures - #40467
Merged
Merged
Conversation
…oFn closures A user transform's DoFn that captures `self` also captures the closures YAML patches onto it, which hold the Scope and every provider. Any unpicklable provider state (e.g. a protobuf Descriptor) then makes pickling fail. This test injects such state to reproduce the flaky ErrorHandlingTest failures deterministically.
Collaborator
Author
|
r: @derrickaw as the author of the previous attempt (#39845). |
shunping
marked this pull request as ready for review
October 8, 2026 16:08
Contributor
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
derrickaw
approved these changes
Oct 8, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40467 +/- ##
=============================================
+ Coverage 56.20% 79.55% +23.34%
=============================================
Files 1123 487 -636
Lines 178213 82238 -95975
Branches 1489 0 -1489
=============================================
- Hits 100168 65422 -34746
+ Misses 75524 16816 -58708
+ Partials 2521 0 -2521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes flaky
ErrorHandlingTest.test_error_handling_outputsandErrorHandlingTest.test_strip_error_metadatainyaml_transform_test.py, which intermittently fail with:Root cause
Scope.create_ptransformmonkey-patchesannotationsandexpandonto the user's transform instance. The patchedexpand(recording_expand) closes over the YAMLScope, which references every provider, including the process-globalstandard_providers()(cached viafunctools.cache).SizeLimiter'sraise_on_bigusesself._limit) therefore pickles the whole Scope and all providers. Providers hold lazily-populated, process-wide state (e.g.ExternalProvider._service/_schema_transforms), so whether the pickle succeeds depends on which tests ran earlier on the same xdist worker. Hence the flakiness.SizeLimiterclosure is ~90 KB and contains the Scope, 28ExternalJavaProviders, 20RenamingProviders, etc., all to carry a single int.Fix
Add
Scope.__reduce__returning a string stub, mirroring the existingPipeline.__reduce__.The Scope is only used during pipeline construction:
recording_expandonly runs duringrunner.apply_PTransform; workers never call a composite'sexpand.PICKLED_TRANSFORMare never re-expanded.This keeps the existing monkey-patching unchanged, so there's no change to transform labels (update compatibility) or to type-hint behavior. After the fix, the pickled closure drops from ~90 KB to ~3.9 KB.