Skip to content

fix(core): resolve User model infinite recursion depth when decoding … - #436

Merged
zikani03 merged 1 commit into
openimis:OP-3108-Core-Login-caused-infinite-recursion-depthfrom
sunilparajuli:OP-3108-Core-Login-caused-infinite-recursion-depth
Aug 3, 2026
Merged

fix(core): resolve User model infinite recursion depth when decoding …#436
zikani03 merged 1 commit into
openimis:OP-3108-Core-Login-caused-infinite-recursion-depthfrom
sunilparajuli:OP-3108-Core-Login-caused-infinite-recursion-depth

Conversation

@sunilparajuli

@sunilparajuli sunilparajuli commented Aug 2, 2026

Copy link
Copy Markdown
Member

…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 RecursionError trap inside the core User model proxy that crashes GraphQL requests and JWT decoders when attempting to lazily fetch deferred InteractiveUser relations.
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"}.

  • The JWT decoder backend optimizes token resolution by fetching the database user via .only("i_user__private_key"). This defers all other relation IDs (like i_user_id).
  • When Django internals (refresh_from_db) interact with these lazily-loaded models, they perform checks like hasattr(self, "_prefetched_objects_cache").
  • The custom User.__getattr__ interceptor failed to reject these internal checks, wrongfully proxying them to self._u and self.i_user. This triggered the deferred fields to refresh themselves from the DB... which immediately evaluated _prefetched_objects_cache again, causing infinite recursion.

Solution

  • Added a short-circuit guard in core/models/user.py:User.__getattr__ to instantly raise an AttributeError for any property beginning with an underscore (_).
  • This allows Django's internal state queries to gracefully fall back without getting trapped by the self._u proxy wrapper.

Type of Change

  • Feature
  • Bug fix
  • Chore (Refactor, Docs, CI/CD)
  • Other, please specify

Related Issue(s) / Task(s)

  • Requires [link to github PR], [link to github PR] needs to be merged first before this one
  • Relates to [link to github PR], this needs to be merged before [link to github PR]
  • External reference (e.g., Jira):

Demo

Upload screenshots/gifs or link to any demo video here.

Checklist

  • Unit tests added/modified
  • I18n / translation handled

@zikani03
zikani03 merged commit 7cedfe7 into openimis:OP-3108-Core-Login-caused-infinite-recursion-depth Aug 3, 2026
3 of 5 checks passed
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.

2 participants