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

feat(backup): Generate cloned QuerySubscription on import #56023

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

azaslavsky
Copy link
Contributor

To avoid creating duplicate subscription_ids, rather than naively copying in imported model data, we instead take this data to construct a new call to create_snuba_subscription. This will generate an identical subscription (modulo creation/edit dates, which we overwrite), but with a new subscription_id.

Closes getsentry/team-ospo#193

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #56023 (010e70e) into master (b32f3e0) will increase coverage by 13.32%.
Report is 2 commits behind head on master.
The diff coverage is 48.27%.

❗ Current head 010e70e differs from pull request most recent head c4e56c6. Consider uploading reports for the commit c4e56c6 to get more accurate results

@@             Coverage Diff             @@
##           master   #56023       +/-   ##
===========================================
+ Coverage   66.67%   79.99%   +13.32%     
===========================================
  Files        5063     5066        +3     
  Lines      217573   218017      +444     
  Branches    36828    36898       +70     
===========================================
+ Hits       145061   174398    +29337     
+ Misses      66929    38270    -28659     
+ Partials     5583     5349      -234     
Files Changed Coverage
src/sentry/models/projectkey.py ø
src/sentry/testutils/helpers/backups.py 0.00%
src/sentry/models/orgauthtoken.py 28.00%
src/sentry/snuba/models.py 40.00%
src/sentry/backup/comparators.py 86.66%
src/sentry/backup/findings.py 100.00%


# Keep the original dates.
subscription.date_added = self.date_added
subscription.date_updated = self.date_updated
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to have a new date_updated here instead of using the old value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right - I've removed this line.

if old_pk is None:
return None

subscription = create_snuba_subscription(self.project, self.type, self.snuba_query)
Copy link
Member

Choose a reason for hiding this comment

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

Previously, were imports for this working at all? Wondering if there was some setup missing that create_snuba_subscription does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see how they would have worked. This is one of the (many) ways that old import/export was broken.

Base automatically changed from azaslavsky/backup/org_auth_token to master September 14, 2023 16:05
To avoid creating duplicate `subscription_id`s, rather than naively
copying in imported model data, we instead take this data to construct a
new call to `create_snuba_subscription`. This will generate an identical
subscription (modulo creation/edit dates, which we overwrite), but with
a new `subscription_id`.

Closes getsentry/team-ospo#193
@azaslavsky azaslavsky force-pushed the azaslavsky/backup/query_subscription branch from 010e70e to c4e56c6 Compare September 14, 2023 16:11
@azaslavsky azaslavsky marked this pull request as ready for review September 14, 2023 16:11
@azaslavsky azaslavsky requested review from a team as code owners September 14, 2023 16:11
@azaslavsky azaslavsky enabled auto-merge (squash) September 14, 2023 16:11
@azaslavsky azaslavsky merged commit 2aa2ad0 into master Sep 14, 2023
50 checks passed
@azaslavsky azaslavsky deleted the azaslavsky/backup/query_subscription branch September 14, 2023 16:42
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 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.

Properly handle unique=True field collisions on import
2 participants