KartikGupta2007 opened a new pull request, #41949:
URL: https://github.com/apache/beam/pull/41949
fixes #20942
With `def process(self, element, an_arg='x', w=DoFn.WindowParam)` and no
value for `an_arg`, Beam passed the window into `an_arg`, and `w` got the
`DoFn.WindowParam` placeholder object. Passing `an_arg` as a keyword raised
`TypeError: process() got multiple values for argument 'an_arg'`.
`_get_arg_placeholders` builds the positional argument list for `process()`.
When a plain default argument had no positional value left, it appended
nothing, so every placeholder after it moved one slot to the left.
Now such an argument is recorded as unfilled:
- Unfilled arguments at the end are dropped, as before, so Python still
applies their defaults and keyword values.
- An unfilled argument before a placeholder gets its keyword value (removed
from the kwargs, so it is not passed twice) or its default.
This runs once when the invoker is built, not per element.
Not changed: a side input passed by keyword into such a slot
(`an_arg=beam.pvalue.AsSingleton(...)`) still raises the same `TypeError` as on
master, because `insert_values_in_args` fills positional side inputs first and
then the sorted kwargs.
Tests:
- New `test_dofn_process_default_arg_before_window_param` in
`runners/common_test.py` (default, positional, keyword, positional side input).
The default and keyword cases fail on master.
- `pytest -n 8` on `runners/common_test.py`,
`transforms/sideinputs_test.py`, `transforms/ptransform_test.py`,
`transforms/core_test.py`, `transforms/userstate_test.py`,
`transforms/batch_dofn_test.py`,
`runners/portability/fn_api_runner/fn_runner_test.py` and
`transforms/util_test.py`: 1027 passed, 89 skipped.
- `yapf==0.43.0` and `ruff==0.17.6` are clean on the changed files.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]