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

Remove SQLUserData when removing domain membership #36000

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

gherceg
Copy link
Contributor

@gherceg gherceg commented Mar 18, 2025

Product Description

Technical Summary

https://dimagi.atlassian.net/browse/SAAS-16810

Stumbled upon this issue when testing the dump and restore. We currently leave SQLUserData in an "orphaned" state when removing domain memberships, where a user still has SQLUserData associated with a domain they are no longer a part of.

This could lead to confusion if the user is re-added to this domain in the future as this SQLUserData will still be referenced/used. I think the more appropriate behavior is to cleanup any SQLUserData associated with a user and domain when removing that user from that domain.

Feature Flag

Safety Assurance

Safety story

This user data isn't useful once a user is no longer part of a domain.

Automated test coverage

Added tests to ensure deleting a domain membership cleans up SQLUserData as expected.

QA Plan

No

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@gherceg gherceg force-pushed the gh/remove-user-data branch from 2c4975c to 45dfe2c Compare March 18, 2025 21:00
@gherceg gherceg marked this pull request as ready for review March 19, 2025 18:14
@gherceg gherceg requested a review from esoergel as a code owner March 19, 2025 18:14
@gherceg gherceg added the Open for review: do not merge A work in progress label Mar 21, 2025
@gherceg
Copy link
Contributor Author

gherceg commented Mar 21, 2025

Realized I need to soft delete user data first as there is a workflow to restore a domain membership just after removing a user from a domain. So that blocks this PR from being merged for now. Created #36045 and once merged, can update this PR to soft delete instead.

@gherceg
Copy link
Contributor Author

gherceg commented Mar 25, 2025

I don't love the direction this is going. I initially thought this would be a quick fix, but am realizing it is hard to make this change without impacting a lot of code. There is a unique constraint on user + domain on SQLUserData, hence needing to delete any soft deleted user data when adding a new domain membership.

I would say my confidence is in this change is low at the moment, and I would need to spend more time digging into this and probably run the change through QA to feel better about it.

@dimagimon dimagimon added the reindex/migration Reindex or migration will be required during or before deploy label Mar 26, 2025
Copy link
Contributor

@jingcheng16 jingcheng16 left a comment

Choose a reason for hiding this comment

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

Looks good to me but can resonate your lack of confidence 😂 Recommend to do QA~~~ Though I don't know how can QA check the correct state of SQLUserData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Open for review: do not merge A work in progress reindex/migration Reindex or migration will be required during or before deploy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants