-
Notifications
You must be signed in to change notification settings - Fork 460
fix(data-classes): ensure lazy initialization for Cognito token generation response properties #7653
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
base: develop
Are you sure you want to change the base?
Conversation
…ation responses Fixed inconsistent lazy initialization in PreTokenGenerationTriggerEventResponse and PreTokenGenerationV2TriggerEvent response properties. Properties now consistently initialize empty dictionaries in _data when None, preventing None returns and ensuring modifications persist correctly. Affects: claims_override_details, claims_scope_override_details, id_token_generation, and access_token_generation properties.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
Hi @nc-dirknilius ! Thanks for the PR, I see some checks are failing, can you address them? let me know if you need any help |
Hi @anafalcao, I fixed the linter finding. Pls re-check. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7653 +/- ##
========================================
Coverage 96.52% 96.52%
========================================
Files 275 275
Lines 13117 13123 +6
Branches 986 990 +4
========================================
+ Hits 12661 12667 +6
Misses 353 353
Partials 103 103 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
Assigning to me to review this by Monday. |



Issue number: closes #7651
Summary
Fixed lazy initialization behavior in Cognito User Pool Pre Token Generation trigger event response properties to ensure consistent state management and prevent None return values when accessing nested token configuration objects.
The
PreTokenGenerationTriggerEventResponseandPreTokenGenerationV2TriggerEventresponse classes had inconsistent lazy initialization behavior:In
ClaimsAndScopeOverrideDetails, theid_token_generationandaccess_token_generationproperties could returnNonewhen the underlying data didn't exist yet, forcing users to handle None cases.In
PreTokenGenerationTriggerEventResponse.claims_override_detailsandPreTokenGenerationTriggerV2EventResponse.claims_scope_override_details, the properties usedself.get()which created a new dictionary on every access instead of initializing the underlying_datadictionary once.This meant that modifications to nested properties wouldn't persist correctly, as each property access would create a fresh wrapper around a new empty dictionary rather than modifying the event's actual data structure.
Changes
Updated the property implementations to use consistent lazy initialization pattern:
Changed
id_token_generationandaccess_token_generationproperties from returningTokenClaimsAndScopeOverrideDetails | Noneto always returningTokenClaimsAndScopeOverrideDetailsby initializing an empty dict in_dataif not present.Modified
claims_override_detailsandclaims_scope_override_detailsproperties to check and initialize their respective keys inself._data(instead of usingself.get()), ensuring all modifications are made to the same underlying dictionary that will be included in the final event response.This aligns with the existing pattern used in other trigger event response classes and ensures that users can chain property access and modifications without encountering None values or losing changes.
test_cognito_pre_token_generation_trigger_event: Validates thatclaims_override_detailsproperties can be accessed and modified, with changes persisting through the event objecttest_cognito_pre_token_v2_generation_trigger_event: Validates thatclaims_scope_override_detailsand its nestedid_token_generationandaccess_token_generationproperties can be accessed and modified with proper persistence of changesUser experience
The user can now properly use the class:
This was not working before as stated above. Even though there was some tests around that feature, the tests implemented poorly and covered the actual problem. The tests where updated to actually test the final event data.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.