Skip to content

fix: add _aes attribute to Fernet256 for cryptography>=50.0.0 compatibility - #16654

Open
mjohns91 wants to merge 2 commits into
ansible:develfrom
mjohns91:fix-fernet256-cryptography-50-compat
Open

mjohns91 wants to merge 2 commits into
ansible:develfrom
mjohns91:fix-fernet256-cryptography-50-compat

Conversation

@mjohns91

@mjohns91 mjohns91 commented Sep 14, 2026

Copy link
Copy Markdown

Issue Type

  • Bug, Docs Fix or other nominal change

Summary

Fixes Fernet256 class to be compatible with cryptography>=50.0.0.

Problem

Cryptography 50.0.0 added a self._aes attribute to the Fernet class constructor. Since Fernet256 overrides __init__() without calling super().__init__(), it doesn't get this attribute.

This causes 277 test failures in the AWX test suite when using cryptography>=50.0.0:

AttributeError: 'Fernet256' object has no attribute '_aes'

The error occurs in any code path that uses Fernet256 for encryption/decryption (credentials, secrets, etc.).

Solution

This PR:

  • Imports algorithms from cryptography.hazmat.primitives.ciphers
  • Sets self._aes = algorithms.AES(self._encryption_key) in Fernet256.__init__()

Backward Compatibility

✅ This fix is backward compatible with cryptography < 50.0.0 because:

  • The _aes attribute wasn't used by Fernet's methods in older versions
  • Setting it doesn't break any existing functionality
  • No changes to the public API

Testing

This fix resolves the 277 test failures when running AWX tests with cryptography==50.0.1.

Related

…bility

Cryptography 50.0.0 added a self._aes attribute to the Fernet class
constructor. Since Fernet256 overrides __init__ without calling
super().__init__(), it needs to manually set this attribute.

Without this attribute, any code using Fernet256 (encryption/decryption
of credentials, secrets, etc.) fails with:
    AttributeError: 'Fernet256' object has no attribute '_aes'

This fix:
- Imports algorithms from cryptography.hazmat.primitives.ciphers
- Sets self._aes = algorithms.AES(self._encryption_key) in __init__

The fix is backward compatible with cryptography < 50.0.0 since the
_aes attribute wasn't used by Fernet's methods in older versions.

Fixes: 277 test failures in AWX test suite when using cryptography 50.x
Related: pyca/cryptography#11234 (cryptography 50.0.0 changes)
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4ba052b5-3b93-44d1-8701-4cf91dad5078

📥 Commits

Reviewing files that changed from the base of the PR and between 88faef6 and df2ecd0.

📒 Files selected for processing (1)
  • awx/main/utils/encryption.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Fernet256 now creates an AES instance from its encryption key. The change adds the required AES import and supports cryptography 50.0.0 and later.

Changes

Fernet256 compatibility

Layer / File(s) Summary
Add AES initialization
awx/main/utils/encryption.py
The module imports cryptography’s AES algorithm. Fernet256.__init__ creates and stores an AES instance from the encryption key.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6a4f5

This change addresses the reported encryption and decryption compatibility failures without introducing a remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding the _aes attribute for cryptography 50.0.0 and later compatibility.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@aap-pde-ci-bot

Copy link
Copy Markdown

❌ Test Results - FAILED

Summary

Metric Count
Total Tests 613
✅ Passed 559
❌ Failed 2
⚠️ Errors 2
⏭️ Skipped 50
⏱️ Duration 3006.19s

Pass Rate: 91.2%

❌ Failed Tests

Test Class
test_constructed_inventory_basic_aggregation opt.test-suite.tests.inventories.test_constructed_control_plane.TestConstructedInventoryControlPlane
test_constructed_inventory_basic_aggregation opt.test-suite.tests.inventories.test_constructed_control_plane.TestConstructedInventoryControlPlane
test_jt_allows_to_set_timeout_when_prompt_is_enabled[0] opt.test-suite.tests.prompts.test_prompts_timeout.TestPromptTimeout
test_jt_allows_to_set_timeout_when_prompt_is_enabled[0] opt.test-suite.tests.prompts.test_prompts_timeout.TestPromptTimeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants