fix(backup): Fix query logic for dangling model exports #57737
Merged
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.
There are a small number of models that have no unambiguous direct connection to their relocation scope's root model - these are called "dangling" models. The key factor that defines them, and makes them difficult to handle, is that we cannot use our "query already exported foreign keys" filtering methodology to select only the models relevant to our export targets, because these models have no foreign keys that connect them back to the root of that target. For example,
TimeSeriesSnapshot
has no foreign keys at all, see: https://tinyurl.com/27z4x6tk.In cases like the one above, we ended up exporting ALL of the
TimeSeriesSnapshot
s in the database - clearly a very bad outcome when we only want to export those related to a specific org! A better approach is to define custom filtering logic for these models, thereby enabling them to use "adjacent" models in the model graph to select only models that we care about for a given export. In the example above, we query allIncident
s filtered down by our previous exports to get a sneak-peek at the set ofIncidentSnapshot
s (a set that is currently empty due to going in reverse dependency order), then use that information to work backwards to grab theTimeSeriesSnapshot
s we need.The upshot is that this commit introduces a generic method for constructing filtered queries for a specific model, the overridable
query_for_relocation_export
.Issue: getsentry/team-ospo#203