Skip to content

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

Merged
Alam-2U merged 1 commit intorelease-ulmofrom
cosmo2-917
Apr 22, 2026
Merged

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

Conversation

@Alam-2U
Copy link
Copy Markdown
Collaborator

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

Description

After migrating the forum backend from MongoDB to MySQL, user retirement via the retire_forum API was failing due to MySQL-specific constraints that were not handled correctly in the existing implementation.


Issues Identified

  1. Foreign Key Constraint Violation

    • The update_user logic attempted to delete ReadState (parent) records before deleting associated LastReadTime (child) records.
    • MySQL enforces referential integrity, preventing deletion of parent records while dependent child records exist.
    • This resulted in IntegrityError during user retirement.
  2. Duplicate Email Constraint Violation

    • Legacy logic (inherited from MongoDB flow) sets auth_user.email = "" during user retirement.
    • In MySQL, the email field has a UNIQUE constraint, and multiple empty strings violate this constraint.
    • This caused duplicate key errors when retiring multiple users.

Changes Made

  • Fixed deletion order to maintain referential integrity

    • Explicitly delete LastReadTime (child records) before deleting ReadState (parent records).
  • Removed email update from MySQL backend

    • Stopped setting auth_user.email = "" during user retirement.
    • Email handling is already managed by LMS, making this update redundant and unsafe for MySQL.

Ticket

COSMO2-917

@Alam-2U Alam-2U changed the title fix :MySQL Referential Integrity Error in update_user During retire_f… fix: mysql referential integrity error in update_user during retire_forum Apr 22, 2026
@Alam-2U Alam-2U requested a review from Copilot April 22, 2026 11:13
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 MySQL-specific failures in the retire_forum user retirement flow after the forum backend migration from MongoDB to MySQL, addressing referential integrity and uniqueness constraints.

Changes:

  • Adjusts deletion order for ReadState/LastReadTime cleanup to avoid MySQL FK constraint violations.
  • Stops updating auth_user.email in the MySQL backend during update_user (to avoid MySQL UNIQUE constraint collisions).
  • Bumps package version to 0.5.1.

Reviewed changes

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

File Description
forum/backends/mysql/api.py Alters update_user behavior for retirement (read-state cleanup ordering and email handling).
forum/__init__.py Version bump reflecting 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/backends/mysql/api.py
Copy link
Copy Markdown

@Akanshu-2u Akanshu-2u left a comment

Choose a reason for hiding this comment

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

lgtm!

@Alam-2U Alam-2U merged commit 5fee94e into release-ulmo Apr 22, 2026
17 checks passed
@Alam-2U Alam-2U deleted the cosmo2-917 branch April 22, 2026 12:14
Alam-2U added 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.
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.

5 participants