Skip to content

fix: mysql referential integrity error in update_user during retire_forum#39

Merged
Alam-2U merged 1 commit intorelease-ulmofrom
ealam/cosmo2-917
Apr 23, 2026
Merged

fix: mysql referential integrity error in update_user during retire_forum#39
Alam-2U merged 1 commit intorelease-ulmofrom
ealam/cosmo2-917

Conversation

@Alam-2U
Copy link
Copy Markdown
Collaborator

@Alam-2U Alam-2U commented Apr 23, 2026

Description

After migrating the forum backend from MongoDB to MySQL, the retire_forum API started failing due to MySQL-specific referential integrity constraints that were not properly handled in the existing implementation.

A previous fix was introduced in PR #38, but the issue persists. The failure occurs because user.save() attempts to update the email field in the auth_user table, which has already been modified by LMS, leading to conflicts.

This PR addresses the issue by ensuring that updates to auth_user do not violate existing constraints and by aligning the deletion/update flow with MySQL’s referential integrity requirements.

Ticket

COSMO2-917

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes user retirement failures after the MongoDB → MySQL migration by preventing unintended updates to auth_user fields that can violate MySQL constraints during retire_forum.

Changes:

  • Limit Django User.save() calls in the MySQL backend to only update username (via update_fields) and skip saving when no user fields changed.
  • Adjust the retire-user flow to only blank email for non-MySQL backends (MongoDB), since LMS owns auth_user.email in the MySQL deployment.
  • Bump package version to 0.5.2.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
forum/backends/mysql/api.py Restricts User.save() to username updates (and only when needed) to avoid touching email and triggering constraint issues.
forum/api/users.py Makes retirement email-blanking conditional by backend type (MongoDB vs MySQL).
forum/__init__.py Version bump to reflect the fix release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread forum/backends/mysql/api.py
Comment thread forum/api/users.py
@Alam-2U Alam-2U merged commit 028ab29 into release-ulmo Apr 23, 2026
13 checks passed
@Alam-2U Alam-2U deleted the ealam/cosmo2-917 branch April 23, 2026 12:18
naincy128 pushed a commit that referenced this pull request Apr 23, 2026
…orum (#39)

A previous fix was introduced in PR #38, but the issue persists. The failure occurs because user.save() attempts to update the email field in the auth_user table, which has already been modified by LMS, leading to conflicts.
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