Skip to content

[Python] Initialize Fernet in MockNoOpDecrypt.setup() for cryptography 51 - #41870

Merged
shunping merged 1 commit into
masterfrom
fix/gbek-test-fernet-setup-46783808936
Dec 2, 2026
Merged

shunping merged 1 commit into
masterfrom
fix/gbek-test-fernet-setup-46783808936

Conversation

@damccorm

@damccorm damccorm commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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:

  • The PR is an appropriate fix for the issue (e.g. we're not changing a test to avoid a bug)
  • The PR is a simple fix to the issue (e.g. we're not adding infra when we could just modify a test)
  • The PR is not covering for other problems (e.g. if we're bumping timeouts, it is not because we're covering for a performance problem)

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_encryption and GroupByEncryptedKeyTest.test_gbek_fake_secret_manager_actually_does_encryption failing across all Python CI workflows under cryptography==51.0.0 (TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.fernet.Fernet' object).

Failing master Runs (3 occurrences)

Root Cause

cryptography==51.0.0 replaced Python Fernet with a Rust-backed cryptography.hazmat.bindings._rust.fernet.Fernet object that is not picklable. Production DoFns _EncryptMessage (util.py:350) and _DecryptMessage (util.py:387) already construct Fernet in setup(), but test subclass MockNoOpDecrypt (util_test.py:260) constructed self.fernet_tester = Fernet(hmac_key) in __init__(), which fails during pipeline serialization.

Changes

  • sdks/python/apache_beam/transforms/util_test.py: Moved self.fernet_tester = Fernet(...) from MockNoOpDecrypt.__init__() to MockNoOpDecrypt.setup() (calling super().setup() first), matching _DecryptMessage.
  • Disjoint file note: Open PR [Python] Fix the output type hints of Reify.Window, WindowInValue and TimestampInValue #41320 also edits util_test.py, strictly at lines 90 (Timestamp import) and 3016+ (Reify tests), >2,750 lines away from MockNoOpDecrypt (lines 257–268).

Verification

  • Verified syntax locally (python3 -m py_compile).
  • Dispatched beam_PreCommit_Python_Transforms.yml (and Python tests / PreCommit Python Coverage run automatically on this PR).

Verification

  • Triggered .github/workflows/beam_PreCommit_Python_Transforms.yml workflow run on branch: 46794545782

@damccorm damccorm added the test-failure-cleanup Automated test health and flake cleanup PRs label Dec 2, 2026
@damccorm

damccorm commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@github-actions github-actions Bot 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.

📋 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() in MockNoOpDecrypt.setup() properly initializes self.fernet on the parent _DecryptMessage class while avoiding pickling Fernet instances during pipeline serialization.
  • Note that super().setup() already sets self.fernet = Fernet(hmac_key), so self.fernet_tester is technically redundant with self.fernet, though keeping self.fernet_tester preserves existing test structure with minimal diff.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.88%. Comparing base (5307bd5) to head (356dddb).
⚠️ Report is 6 commits behind head on master.

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     
Flag Coverage Δ
python 80.75% <ø> (+27.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@damccorm damccorm added the ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review label Dec 2, 2026
@damccorm
damccorm marked this pull request as ready for review December 2, 2026 14:52
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label python.
Backup reviewer: tvalentyn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

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

@shunping
shunping merged commit 12376b7 into master Dec 2, 2026
96 checks passed
@damccorm
damccorm deleted the fix/gbek-test-fernet-setup-46783808936 branch December 2, 2026 15:53
shikhabhadoria added a commit to shikhabhadoria/beam that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Next Action: Reviewers python ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review size/xs XS: <10 lines changed test-failure-cleanup Automated test health and flake cleanup PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants