Skip to content

Conversation

@kcons
Copy link
Member

@kcons kcons commented Nov 8, 2025

To be properly imported from backup (as with self-host to saas migration) DataSource needs to remap ids to new values.
This involves tracking dependencies and translating in normalize_before_relocation_import.
The field comparator has to be somewhat lax here, as the actual foreign item referenced is dependent on two fields, which isn't really a pattern supported by our ForeignKey comparator infrastructure. For now, at least, we assume the fields being referenced are valid (a big improvement over the current prod code, where we have broken id references and also ignore that), but this will be revisited in a follow-up.

@kcons kcons requested review from a team as code owners November 8, 2025 00:07
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 8, 2025
@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 92.98246% with 4 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/workflow_engine/models/data_source.py 86.36% 3 Missing ⚠️
src/sentry/uptime/models.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #103002      +/-   ##
===========================================
+ Coverage   80.58%    80.83%   +0.24%     
===========================================
  Files        8937      8950      +13     
  Lines      391228    392336    +1108     
  Branches    24887     24887              
===========================================
+ Hits       315277    317136    +1859     
+ Misses      75581     74830     -751     
  Partials      370       370              

@kcons kcons requested a review from cathteng November 11, 2025 21:07
Comment on lines +33 to +34
# DataSource.source_id dynamically references different models based on the 'type' field.
# We declare all possible dependencies here to ensure proper import ordering.
Copy link
Member

Choose a reason for hiding this comment

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

Does the order matter because we need the pk mappings for the other tables to exist before this table is relocated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Comment on lines 81 to 82
# Referenced model not in pk_map. This may be correct (reset_pks=False) or broken
# (reset_pks=True but referenced model was filtered out or failed to import).
Copy link
Member

Choose a reason for hiding this comment

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

Should we return None if we can't map the source_id? I think with this logic it will keep this object mapped to the old source_id, which could be inaccurate?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should, and now we do. I got confused by test logic, but now know better.

Comment on lines +741 to +743
DataSource.source_id is a dynamic foreign key that gets remapped during import via the
normalize_before_relocation_import method. Since the remapping is handled there, we just
need to verify that both sides have a valid source_id value, without comparing the actual values.
Copy link
Member

Choose a reason for hiding this comment

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

nice

@kcons kcons merged commit dfebf30 into master Nov 12, 2025
66 checks passed
@kcons kcons deleted the kcons/remap branch November 12, 2025 19:45
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
…03002)

To be properly imported from backup (as with self-host to saas
migration) DataSource needs to remap ids to new values.
This involves tracking dependencies and translating in
normalize_before_relocation_import.
The field comparator has to be somewhat lax here, as the actual foreign
item referenced is dependent on two fields, which isn't really a pattern
supported by our ForeignKey comparator infrastructure. For now, at
least, we assume the fields being referenced are valid (a big
improvement over the current prod code, where we have broken id
references and also ignore that), but this will be revisited in a
follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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