fix: prevent early return in PathList lookup when intermediate path fails#81
Open
fix: prevent early return in PathList lookup when intermediate path fails#81
Conversation
…ails When `get_path_in_dict` received a PathList (list of lists) and the first path encountered a missing key at an intermediate segment, the function returned `None` immediately instead of trying the remaining paths. The root cause was `return None` inside the inner loop's `not isinstance(r, dict)` guard. This aborted the entire outer loop rather than just the current path. Replaced with `break` and moved the result check into a `for/else` block so that only fully traversed paths are considered. Made-with: Cursor
7258973 to
d6e3415
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 83.08% 83.18% +0.09%
==========================================
Files 18 18
Lines 1874 1885 +11
Branches 193 193
==========================================
+ Hits 1557 1568 +11
Misses 234 234
Partials 83 83
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
jason-famedly
approved these changes
Apr 3, 2026
Member
jason-famedly
left a comment
There was a problem hiding this comment.
Apologizes for the length of time it took me to understand enough of the code base to understand what this was even for. This should be fine 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_path_in_dictwhere a PathList with multiple paths would short-circuit on the first failing path instead of trying subsequent ones.return Noneaborted the entire function. Changed tobreak+for/elseso only fully traversed paths produce a result.admin_pathscenario with project-scoped role claims.Context
When
admin_pathis configured as a PathList (e.g.[["roles", "Admin"], ["urn:zitadel:iam:org:project:<id>:roles", "MatrixAdmin"]]), the first path["roles", "Admin"]fails on tokens that don't have aroleskey. The bug caused the function to returnNoneimmediately without ever checking the second path, making it impossible to use PathList for fallback admin detection.Test plan
test_get_path_in_dictassertions still passtest_get_path_in_dict_pathlist_fallback_on_missing_key— verifies fallback when the first path's key is entirely absenttest_get_path_in_dict_pathlist_non_dict_intermediate— verifies fallback when an intermediate value is a non-dict (int, string)test_get_path_in_dict_zitadel_admin_path— real-world scenario with Zitadel project-scoped role claims, testing both path orderingsMade with Cursor