-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Added function for deterministic ID for class definitions by hashing. #36793
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
Conversation
Summary of ChangesHello @praneetnadella, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a robust mechanism for generating deterministic identifiers for Python class definitions, primarily by hashing their serialized form. It also enhances the internal class tracking system to safely handle recursive ID generation attempts and improves thread safety, ensuring more reliable and predictable behavior during class serialization. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #36793 +/- ##
=========================================
Coverage 40.28% 40.28%
+ Complexity 3457 3456 -1
=========================================
Files 1223 1223
Lines 187539 187557 +18
Branches 3587 3586 -1
=========================================
+ Hits 75546 75555 +9
- Misses 108601 108612 +11
+ Partials 3392 3390 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @jrmccluskey for label python. 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). |
|
assign to next reviewer |
|
R: @claudevdm |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
|
/gemini review |
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.
Code Review
This pull request introduces a function for generating deterministic IDs for class definitions by hashing their pickled representation. The changes are well-implemented, including the use of threading.RLock to prevent deadlocks during recursive pickling and a sentinel value to detect and handle recursive ID generation for the same class. The error handling within _get_or_create_tracker_id is also robust, ensuring that the state is cleaned up on exceptions. I have a couple of suggestions for improvement regarding exception handling specificity and a small typo.
| except: | ||
| _DYNAMIC_CLASS_TRACKER_BY_CLASS.pop(class_def, None) | ||
| raise |
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.
Using a bare except: can catch more exceptions than intended, such as SystemExit or KeyboardInterrupt, which can hide bugs or make it harder to stop the program. It's better to be more specific and catch Exception instead to avoid unintentionally swallowing system-level exceptions.
| except: | |
| _DYNAMIC_CLASS_TRACKER_BY_CLASS.pop(class_def, None) | |
| raise | |
| except Exception: | |
| _DYNAMIC_CLASS_TRACKER_BY_CLASS.pop(class_def, None) | |
| raise |
| hexidgest = hashlib.sha256( | ||
| dumps(classdef, config=CloudPickleConfig(id_generator=None))).hexdigest() | ||
| return hexidgest |
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.
There's a typo in the variable name hexidgest; it should be hexdigest.
Additionally, this change removes the trailing newline from the file. According to PEP 8, files should end with a single newline. Please add one.
| hexidgest = hashlib.sha256( | |
| dumps(classdef, config=CloudPickleConfig(id_generator=None))).hexdigest() | |
| return hexidgest | |
| hexdigest = hashlib.sha256( | |
| dumps(classdef, config=CloudPickleConfig(id_generator=None))).hexdigest() | |
| return hexdigest |
claudevdm
left a comment
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.
LGTM, but @tvalentyn can you take a look (since it is part of the PR i am sending to official cloudpickle repo?)
| CloudPickler = Pickler | ||
|
|
||
|
|
||
| def hash_dynamic_classdef(classdef): |
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.
-
This is seemingly unused?
-
Do we have to worry about (unlikely) hash collisions?
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.
It will be used by flume runner. It is tested in the cloud pickle repo.
Conflicts would be bad, should we try to detect?
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.
Although conflicts should result in unpickling ereor
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.
Although the original uuid approach can also cause collision?
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.
i'd worry if the errors are silenced.
Is detecting cheap? If so, that would help with a cleaner error message. Or if we believe this is really rare, we could add some comment in the codepath that will error-out.
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.
-
The goal is to make this available for use and not called yet as an alternative to id_generator within CPConfig.
-
I feel like since we are using SHA-256 which is pretty collision-resistant, and because a single Beam pipeline will likely have a wide array of variability/complexity in class definitions, the odds are extremely low.
Function by @claudevdm, tested in cloudpickle fork with full suite of tests.
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.