Repository navigation
[Python] Fix stateful ParDo taking the timer key coder from a side input - #40380
Conversation
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
Run Python_Coverage PreCommit 3.10 |
|
Assigning reviewers: R: @jrmccluskey for label python. 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 Available commands:
The PR bot will only process comments in the main thread (not review comments). |
jrmccluskey
left a comment
There was a problem hiding this comment.
This is an interesting bug! Letting the testing runs finish before merging, thanks!
developer-rpai
left a comment
There was a problem hiding this comment.
Good catch — the set subtraction against _SideInput objects could never remove anything, so the "main" tag was hash-order luck, and the timer coder inherited whichever input won. Filtering on the prefix is the right shape, and the AsDict test with mismatched key types is a clean way to prove which input the coder came from. One confirmation: _get_key_and_window_coder now assumes exactly one non-side-input tag — is there any multi-main-input path that reaches it? Also fine to leave, but if every tag carried the prefix this would IndexError where the old code failed differently.
|
@developer-rpai I don't think anything reaches it with more than one. ParDo only takes a single PCollection: applying it to the pipeline/PBegin is rejected at apply time in |
ParDo._get_key_and_window_coderpicked the main input withset(named_inputs.keys()) - set(self.side_inputs). The keys are tag strings andself.side_inputsholds_SideInputobjects, so nothing was ever removed. Which tag came out first depended on set ordering, and so on the hash seed. When it was apython_side_input*tag, the timer family coder got the side input's key coder, orFastPrimitivesCoderif the side input wasAny. On Dataflow that shows up asValueError: Unknown type tagwhen the worker decodes timer keys.This takes the first tag that doesn't start with
SIDE_INPUT_PREFIXinstead. I went with the tag rather than comparing PCollections so it still works when the main input PCollection is also passed as a side input.The new test in
userstate_test.pyuses a stateful DoFn with three dict side inputs keyed by ints and checks that the timer key coder in the proto is the main input'sStrUtf8Coder. Without the fix it failed for 22 of 32 hash seeds locally; with it, none.Fixes #40374
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.