Skip to content

ref(hc): Updates org deletion code to queue an org mapping outbox update #51004

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

Merged
merged 4 commits into from
Jun 15, 2023

Conversation

GabeVillalobos
Copy link
Member

Adds a mark for deletion helper for organizations that queues an update outbox message. Updates the organization deletion API to use this new helper to ensure consistency between our org mappings and organizations

@GabeVillalobos GabeVillalobos requested a review from a team as a code owner June 14, 2023 23:04
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 14, 2023
Comment on lines 51 to 55
org: Organization = Organization.objects.get(id=org_id)
if org.status != OrganizationStatus.ACTIVE:
return None

org.update(status=OrganizationStatus.PENDING_DELETION)
Copy link
Member

Choose a reason for hiding this comment

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

The semantics of a read, then update are slightly different than how the code behaved before where it was an update with condition on the status being active. We have a remote chance of emitting multiple outbox messages and scheduling deletions multiple times, however I don't think it will end up mattering as both those systems handle duplicates well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh because it's an update on the QuerySet before any accesses are made right? I can go ahead and replicate the previous behavior instead to make this atomic.

).update(status=OrganizationStatus.PENDING_DELETION)
if updated:
organization.status = OrganizationStatus.PENDING_DELETION
updated_organization = mark_organization_as_pending_deletion_with_outbox_message(
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should use these functions as the start of a domain layer for organization operations? Several operations for organizations are collecting more behavior that needs to be used as a unit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I personally think we should. I was very tempted to move the scheduling creation here as well since the only 2 references I found essentially tried to maintain their own idempotency so centralizing that here may be a good idea.

@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #51004 (720b387) into master (676339f) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #51004      +/-   ##
==========================================
+ Coverage   81.17%   81.22%   +0.04%     
==========================================
  Files        4877     4886       +9     
  Lines      204602   204912     +310     
  Branches    11128    11128              
==========================================
+ Hits       166081   166430     +349     
+ Misses      38275    38236      -39     
  Partials      246      246              
Impacted Files Coverage Δ
src/sentry/api/endpoints/organization_details.py 90.11% <100.00%> (+0.02%) ⬆️
...services/hybrid_cloud/organization_actions/impl.py 100.00% <100.00%> (ø)

... and 107 files with indirect coverage changes

@GabeVillalobos GabeVillalobos merged commit 6b033d8 into master Jun 15, 2023
@GabeVillalobos GabeVillalobos deleted the fix-deletion-status-not-queueing-outbox branch June 15, 2023 22:23
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants