-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stateful processing using direct runner with type checks enabled #27646
Conversation
R: @tvalentyn |
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control |
Codecov Report
@@ Coverage Diff @@
## master #27646 +/- ##
==========================================
- Coverage 70.87% 70.87% -0.01%
==========================================
Files 861 861
Lines 105001 105005 +4
==========================================
+ Hits 74421 74422 +1
- Misses 29022 29025 +3
Partials 1558 1558
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
options = PipelineOptions() | ||
options.view_as(TypeOptions).runtime_type_check = True | ||
with TestPipeline(options=options) as pipeline: | ||
collection = pipeline \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit / personal opinion: you can use brackets instead of line continuation tokens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, done.
YAPF seems to be way behind black
in this regard, I think I remember seeing somewhere you folks talking about migrating to black, was it a dead end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still on yapf as far as our style infra, idk if anyone is actively investigating alternatives right now
Run Portable_Python PreCommit |
Upon closer look, it seems that current design would still be prone to similar gaps.
I wonder if overriding
|
It falls into a recursion like so:
|
there is also a better example than what I suggested: beam/sdks/python/apache_beam/transforms/core.py Line 2226 in d3ea232
|
Thank you! It worked with a tiny change because of inheritance. Will see whether this passes the whole test suite. |
The unit test that is failing consistently - https://github.com/apache/beam/blob/master/sdks/python/apache_beam/transforms/ptransform_test.py#L2043 - getting So it looks like we're hitting some issues with this type mismatch getting surfaced incorrectly with the change here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test must be passing before merge
Looks like tests are passing. for my education, why was the |
also please update the PR description. |
@@ -49,6 +49,13 @@ def __init__(self, dofn): | |||
super().__init__() | |||
self.dofn = dofn | |||
|
|||
def __getattribute__(self, name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also we should now be able to drop setup
and teardown
overrides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change the setup and teardown are no longer called in here:
beam/sdks/python/apache_beam/typehints/typecheck_test.py
Lines 101 to 122 in 81cd93a
def test_wrapper_pass_through(self): | |
# We use a file to check the result because the MyDoFn instance passed is | |
# not the same one that actually runs in the pipeline (it is serialized | |
# here and deserialized in the worker). | |
with tempfile.TemporaryDirectory() as tmp_dirname: | |
path = os.path.join(tmp_dirname + "tmp_filename") | |
dofn = MyDoFn(path) | |
result = self.p | beam.Create([1, 2, 3]) | beam.ParDo(dofn) | |
assert_that(result, equal_to([1, 2, 3])) | |
self.p.run() | |
with open(path, mode="r") as ft: | |
lines = [line.strip() for line in ft] | |
self.assertListEqual([ | |
'setup', | |
'start_bundle', | |
'process', | |
'process', | |
'process', | |
'finish_bundle', | |
'teardown', | |
], | |
lines) |
Reverted for now: 81cd93a
Any way we can proceed as is? Otherwise please suggest where to start digging, thanks!
This was the easiest fix for
Done! |
Not sure if it makes sense to repeat this check.
Black-style, YAPF doesn't mind.
This makes it more future proof. Inspired by `_ExceptionHandlingWrapperDoFn` but with `type(self)` so that it works with inheritance.
This fixes the test_combine_runtime_type_check_violation_using_methods.
Each is now covered by `__getattribute__`.
I see that some tests are failing now -- I'll take a look next week. |
This reverts commit 27f67df. Coudln't find a way to keep the `RuntimeTypeCheckTest.test_wrapper_pass_through` working except for the following patch: ```diff diff --git a/sdks/python/apache_beam/typehints/typecheck.py b/sdks/python/apache_beam/typehints/typecheck.py index 6d4b4d4962..31d8828fb6 100644 --- a/sdks/python/apache_beam/typehints/typecheck.py +++ b/sdks/python/apache_beam/typehints/typecheck.py @@ -51,7 +51,7 @@ class AbstractDoFnWrapper(DoFn): def __getattribute__(self, name): if (name.startswith('_') or name in self.__dict__ or - hasattr(type(self), name)): + hasattr(type(self), name)) and name not in ('setup', 'teardown'): return object.__getattribute__(self, name) else: return getattr(self.dofn, name) ``` In which case we might as well keep the methods.
Run Portable_Python PreCommit |
Run Python_PVR_Flink PreCommit |
thanks! rerunning remaining suites, feel free to ping this PR if not merged after tests pass. |
With this change all of the public methods of DoFns are now properly proxied from
AbstractDoFnWrapper
, which fixes an issue with using stateful DoFns on direct runner with runtime type checks enabled.Closes #27167
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.md
with 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.