Skip to content

[Python] Fix stateful ParDo taking the timer key coder from a side input - #40380

Merged
jrmccluskey merged 2 commits into
apache:masterfrom
schizophrenicmaniac:fix/40374-bug-pardo-get-key-and-window-coder
Oct 2, 2026
Merged

jrmccluskey merged 2 commits into
apache:masterfrom
schizophrenicmaniac:fix/40374-bug-pardo-get-key-and-window-coder

Conversation

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor

ParDo._get_key_and_window_coder picked the main input with set(named_inputs.keys()) - set(self.side_inputs). The keys are tag strings and self.side_inputs holds _SideInput objects, so nothing was ever removed. Which tag came out first depended on set ordering, and so on the hash seed. When it was a python_side_input* tag, the timer family coder got the side input's key coder, or FastPrimitivesCoder if the side input was Any. On Dataflow that shows up as ValueError: Unknown type tag when the worker decodes timer keys.

This takes the first tag that doesn't start with SIDE_INPUT_PREFIX instead. 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.py uses 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's StrUtf8Coder. 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:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor Author

Run Python_Coverage PreCommit 3.10

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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 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).

@jrmccluskey jrmccluskey 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.

This is an interesting bug! Letting the testing runs finish before merging, thanks!

@developer-rpai developer-rpai 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.

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.

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor Author

@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 Pipeline.apply ("expects a PCollection as input"), and a tuple of PCollections fails in ParDo.expand, both before translation. _named_inputs puts that one main input first and the python_side_input<N> tags after it. After a proto round trip, AppliedPTransform.from_runner_api rebuilds main_inputs the same way, by dropping the side input tags listed in the ParDoPayload. So every tag having the prefix can't really happen for a stateful ParDo. If it somehow did, I'd rather it fail there than quietly take a side input's coder like before.

@jrmccluskey
jrmccluskey merged commit 24d48c9 into apache:master Oct 2, 2026
101 checks passed
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]: ParDo._get_key_and_window_coder fails to filter side inputs when determining main input for stateful DoFns

3 participants