fix(core): resolve User model infinite recursion depth when decoding … - #436
Merged
zikani03 merged 1 commit intoAug 3, 2026
Conversation
zikani03
approved these changes
Aug 3, 2026
zikani03
merged commit Aug 3, 2026
7cedfe7
into
openimis:OP-3108-Core-Login-caused-infinite-recursion-depth
3 of 5 checks passed
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.
…JWT tokens
#Thank you for your contribution to openIMIS!
#Please complete the sections below. Anything in comments is guidance and can be deleted.
Description
This PR fixes an infinite
RecursionErrortrap inside the coreUsermodel proxy that crashes GraphQL requests and JWT decoders when attempting to lazily fetch deferredInteractiveUserrelations.actual error : {"detail":"maximum recursion depth exceeded"}
When authenticating via GraphQL or making requests to
/api/core/users/current_user/, the API returned{"detail": "maximum recursion depth exceeded"}..only("i_user__private_key"). This defers all other relation IDs (likei_user_id).refresh_from_db) interact with these lazily-loaded models, they perform checks likehasattr(self, "_prefetched_objects_cache").User.__getattr__interceptor failed to reject these internal checks, wrongfully proxying them toself._uandself.i_user. This triggered the deferred fields to refresh themselves from the DB... which immediately evaluated_prefetched_objects_cacheagain, causing infinite recursion.Solution
core/models/user.py:User.__getattr__to instantly raise anAttributeErrorfor any property beginning with an underscore (_).self._uproxy wrapper.Type of Change
Related Issue(s) / Task(s)
Demo
Upload screenshots/gifs or link to any demo video here.
Checklist