Skip to content
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

Avoid recursion when a model instance has multiple deferred audit fields #31

Merged
merged 6 commits into from
Jan 18, 2024

Conversation

SmittieC
Copy link
Contributor

@SmittieC SmittieC commented Jan 11, 2024

Deferred fields are loaded by calling 'refresh_from_db'
which in turn calls the model init method. During init, we attempt
to attach initial values for audited fields. If any of the
audited fields are deferred, 'refresh_from_db' is called
again.

This change decorates the refresh_from_db method on models to ensure that
all audited fields are present in the refresh.

An alternative approach to this would be to prevent deferred loading of audited fields in the first place however I'm not sure if that's always possible considering Django uses this internally in some instances e.g. collecting related deleted objects.

Relates to dimagi/open-chat-studio#186

Deferred fields are loaded by calling 'refresh_from_db'
which in turn calls the model init method. During init, we attempt
to attach initial values for audited fields. If any of the
audited fields are deferred, 'refresh_from_db' is called
again.
@snopoke snopoke changed the title Reproduce max recursion depth reached error Avoid recursion when a model instance has multiple deferred audit fields Jan 17, 2024
@snopoke snopoke marked this pull request as ready for review January 17, 2024 12:46
@snopoke snopoke merged commit dd8b0f3 into main Jan 18, 2024
10 checks passed
@snopoke snopoke deleted the cs/max_recursion_error branch January 18, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants