fix: prevent IntegrityError when deleting user account#2234
Closed
Simon99 wants to merge 1 commit intowger-project:masterfrom
Closed
fix: prevent IntegrityError when deleting user account#2234Simon99 wants to merge 1 commit intowger-project:masterfrom
Simon99 wants to merge 1 commit intowger-project:masterfrom
Conversation
Check if user exists before updating statistics in delete signal handlers. This prevents IntegrityError when workout logs/sessions are deleted as part of user deletion cascade. When a user deletes their account, Django cascades the deletion to related objects (WorkoutLog, WorkoutSession). The post_delete signals try to recalculate statistics, but the user no longer exists, causing an IntegrityError on the foreign key constraint. Solution: Check User.DoesNotExist before calling statistics service. Fixes wger-project#2232
Member
|
hey thanks for the PR! however somebody else had already started working on this in #2233 (it seems they started half an hour before you) so I'll close this PR, sorry |
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
Fixes the IntegrityError that occurs when a user deletes their account.
Problem
When a user deletes their account, Django cascades the deletion to related objects (
WorkoutLog,WorkoutSession). Thepost_deletesignal handlers try to recalculate user statistics, but the user no longer exists at that point, causing an IntegrityError:Solution
Added
User.DoesNotExistchecks in both delete signal handlers before attempting to update statistics:workout_log_deleted()- checks if user exists before recalculatingworkout_session_deleted()- checks if user exists before recalculatingIf the user has been deleted, we skip the statistics update and log a debug message.
Changes
wger/trophies/signals.pyworkout_log_deletedworkout_session_deletedTesting
The fix handles the race condition where:
Fixes
Fixes #2232