Repository navigation
[Python] Initialize Fernet in MockNoOpDecrypt.setup() for cryptography 51 - #41870
Conversation
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR moves the Fernet initialization in the MockNoOpDecrypt test helper from __init__() to setup(), addressing a pickling failure introduced in cryptography==51.0.0 where Fernet is backed by an unpicklable Rust object. The change is minimal, clean, and aligns the test subclass with the lifecycle already used in _DecryptMessage and _EncryptMessage.
🔍 General Feedback
- Calling
super().setup()inMockNoOpDecrypt.setup()properly initializesself.ferneton the parent_DecryptMessageclass while avoiding picklingFernetinstances during pipeline serialization. - Note that
super().setup()already setsself.fernet = Fernet(hmac_key), soself.fernet_testeris technically redundant withself.fernet, though keepingself.fernet_testerpreserves existing test structure with minimal diff.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41870 +/- ##
=============================================
+ Coverage 42.25% 58.88% +16.63%
+ Complexity 5182 2334 -2848
=============================================
Files 981 1136 +155
Lines 103824 171059 +67235
Branches 3882 1552 -2330
=============================================
+ Hits 43875 100736 +56861
- Misses 56536 67768 +11232
+ Partials 3413 2555 -858
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @shunping 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). |
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
Full details of the methodology of generation and review can be found here - https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Summary
Fixes
GroupByEncryptedKeyTest.test_gbk_actually_does_encryptionandGroupByEncryptedKeyTest.test_gbek_fake_secret_manager_actually_does_encryptionfailing across all Python CI workflows undercryptography==51.0.0(TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.fernet.Fernet' object).Failing
masterRuns (3 occurrences)Root Cause
cryptography==51.0.0replaced PythonFernetwith a Rust-backedcryptography.hazmat.bindings._rust.fernet.Fernetobject that is not picklable. Production DoFns_EncryptMessage(util.py:350) and_DecryptMessage(util.py:387) already constructFernetinsetup(), but test subclassMockNoOpDecrypt(util_test.py:260) constructedself.fernet_tester = Fernet(hmac_key)in__init__(), which fails during pipeline serialization.Changes
sdks/python/apache_beam/transforms/util_test.py: Movedself.fernet_tester = Fernet(...)fromMockNoOpDecrypt.__init__()toMockNoOpDecrypt.setup()(callingsuper().setup()first), matching_DecryptMessage.util_test.py, strictly at lines 90 (Timestampimport) and 3016+ (Reifytests), >2,750 lines away fromMockNoOpDecrypt(lines 257–268).Verification
python3 -m py_compile).beam_PreCommit_Python_Transforms.yml(andPython tests/PreCommit Python Coveragerun automatically on this PR).Verification
.github/workflows/beam_PreCommit_Python_Transforms.ymlworkflow run on branch:46794545782