ref(db): Migrate create_or_update to update_or_create in five modules#112906
Open
vgrozdanic wants to merge 2 commits intomasterfrom
Open
ref(db): Migrate create_or_update to update_or_create in five modules#112906vgrozdanic wants to merge 2 commits intomasterfrom
vgrozdanic wants to merge 2 commits intomasterfrom
Conversation
Replace the legacy Sentry create_or_update helper with Django's update_or_create across five call sites, removing them from the usage allowlist. - FeatureAdoption: move complete=True into defaults to align with the unique_together constraint on (organization, feature_id) - OrganizationOption.set_value: values= becomes defaults=, always returns True since update_or_create guarantees a row - OrganizationOnboardingTask: values= maps to defaults=, user_id moves to create_defaults for insert-only semantics - Onboarding tasks endpoint: call try_mark_onboarding_complete unconditionally since update_or_create always returns an instance - mockdata: create_or_update with no values becomes get_or_create, defaults= becomes create_defaults= for insert-only field Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-update-or-create-v2
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.
Replace the legacy Sentry
create_or_updatehelper with Django'supdate_or_createacross five call sites, removing them from the usage allowlist.create_or_updatepredates Django'supdate_or_createand is being deprecated. A CI test enforces an allowlist of remaining usages; this PR removes four files from that list.FeatureAdoption —
complete=Truewas in the filter but is not part of theunique_togetherconstraint on(organization, feature_id). Withupdate_or_create, that would cause anIntegrityErrorif a row existed withcomplete=False. Fixed by movingcomplete=Trueintodefaultsso the filter aligns with the unique constraint.OrganizationOption.set_value —
values=→defaults=. The old return valuebool(created) or inst > 0guarded against 0 rows affected, which cannot happen withupdate_or_create— always returnsTruenow.OrganizationOnboardingTask —
values=maps todefaults=(applied on create and update); the create-onlyuser_idmoves tocreate_defaultsmerged withvalues, since Django usescreate_defaultsexclusively for the insert path.Onboarding tasks endpoint —
rows_affectedis no longer meaningful sinceupdate_or_createalways returns an instance.try_mark_onboarding_completeis called unconditionally; it is idempotent (early-exits ifonboarding:completeoption already exists, and deduplicates the analytics event via a unique constraint).mockdata —
create_or_update(member, team)with no values becomesget_or_create;defaults=(which was create-only in the legacy API) becomescreate_defaults=.Supersedes #111784 (rebased fresh on master to avoid stale CI failures).
Requires https://github.com/getsentry/getsentry/pull/19890