Skip to content

Commit

Permalink
ref(backup): More auto-deduced options datetime comparators
Browse files Browse the repository at this point in the history
Previously, we only auto-deduced (from model field types) datetime
equality comparators for fields that were already in the comparator map.
This caused us to miss a lot of datetimes! Now we're more careful about
this, with many more such comparators caught.

I've also removed the snapshot test, and tested the exports directly
instead, ensuring that they always include milliseconds in datetimes.
  • Loading branch information
azaslavsky committed Apr 12, 2024
1 parent 6139b64 commit b1280ef
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 46 deletions.
22 changes: 0 additions & 22 deletions fixtures/backup/datetime-millis.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/sentry/backup/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def auto_assign_datetime_equality_comparators(comps: ComparatorMap) -> None:
fields = e._meta.get_fields()
assign = set()
for f in fields:
if isinstance(f, models.DateTimeField) and name in comps:
if isinstance(f, models.DateTimeField):
# Only auto assign the `DatetimeEqualityComparator` if this field is not mentioned
# by a conflicting comparator.
possibly_conflicting = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ source: tests/sentry/backup/test_comparators.py
- user_id
model_name: sentry.alertrule
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule
Expand All @@ -114,37 +117,55 @@ source: tests/sentry/backup/test_comparators.py
- query_subscription
model_name: sentry.alertruleactivations
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule
- previous_alert_rule
- user_id
model_name: sentry.alertruleactivity
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule
- project
model_name: sentry.alertruleexcludedprojects
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule
- project
model_name: sentry.alertruleprojects
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule
model_name: sentry.alertruletrigger
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule_trigger
- integration_id
- sentry_app_id
model_name: sentry.alertruletriggeraction
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- alert_rule_trigger
Expand All @@ -163,18 +184,27 @@ source: tests/sentry/backup/test_comparators.py
- owner
model_name: sentry.apiapplication
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- application
- user
model_name: sentry.apiauthorization
- comparators:
- class: DatetimeEqualityComparator
fields:
- expires_at
- class: ForeignKeyComparator
fields:
- application
- user
model_name: sentry.apigrant
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- organization_id
Expand Down Expand Up @@ -232,6 +262,10 @@ source: tests/sentry/backup/test_comparators.py
- target_user
model_name: sentry.auditlogentry
- comparators:
- class: DatetimeEqualityComparator
fields:
- created_at
- last_used_at
- class: ForeignKeyComparator
fields:
- user
Expand Down Expand Up @@ -259,6 +293,10 @@ source: tests/sentry/backup/test_comparators.py
- user_id
model_name: sentry.authidentityreplica
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- last_sync
- class: ForeignKeyComparator
fields:
- organization_id
Expand Down Expand Up @@ -332,6 +370,9 @@ source: tests/sentry/backup/test_comparators.py
fields: []
model_name: sentry.controlimportchunkreplica
- comparators:
- class: DatetimeEqualityComparator
fields:
- last_updated
- class: ForeignKeyComparator
fields: []
model_name: sentry.controloption
Expand All @@ -349,6 +390,11 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.counter
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- end_date
- start_date
- class: ForeignKeyComparator
fields:
- created_by_id
Expand All @@ -361,6 +407,10 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.customdynamicsamplingruleproject
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- last_visited
- class: ForeignKeyComparator
fields:
- created_by_id
Expand All @@ -373,11 +423,17 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.dashboardproject
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- organization
model_name: sentry.dashboardtombstone
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- dashboard
Expand Down Expand Up @@ -461,13 +517,19 @@ source: tests/sentry/backup/test_comparators.py
- file_id
model_name: sentry.docintegrationavatar
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: EmailObfuscatingComparator
fields:
- email
- class: ForeignKeyComparator
fields: []
model_name: sentry.email
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- organization_id
Expand Down Expand Up @@ -734,12 +796,18 @@ source: tests/sentry/backup/test_comparators.py
- user_id
model_name: sentry.incidentseen
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- event_stats_snapshot
- incident
model_name: sentry.incidentsnapshot
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- incident
Expand Down Expand Up @@ -844,6 +912,11 @@ source: tests/sentry/backup/test_comparators.py
fields: []
model_name: sentry.monitorlocation
- comparators:
- class: DatetimeEqualityComparator
fields:
- disable_date
- sent_final_email_date
- sent_initial_email_date
- class: ForeignKeyComparator
fields:
- organization
Expand Down Expand Up @@ -1010,6 +1083,10 @@ source: tests/sentry/backup/test_comparators.py
- project_last_used_id
model_name: sentry.orgauthtoken
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- target_run_date
- class: ForeignKeyComparator
fields:
- incident
Expand Down Expand Up @@ -1038,6 +1115,10 @@ source: tests/sentry/backup/test_comparators.py
- project_id
model_name: sentry.proguardartifactrelease
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- first_event
- class: ForeignKeyComparator
fields:
- organization
Expand All @@ -1050,6 +1131,9 @@ source: tests/sentry/backup/test_comparators.py
- project_id
model_name: sentry.projectartifactbundle
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- project
Expand Down Expand Up @@ -1095,6 +1179,10 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.projectoption
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_created
- last_updated
- class: ForeignKeyComparator
fields:
- project
Expand All @@ -1105,6 +1193,9 @@ source: tests/sentry/backup/test_comparators.py
- project_id
model_name: sentry.projectplatform
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- organization
Expand Down Expand Up @@ -1176,6 +1267,10 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.rawevent
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- last_seen
- class: ForeignKeyComparator
fields:
- organization
Expand Down Expand Up @@ -1317,6 +1412,9 @@ source: tests/sentry/backup/test_comparators.py
- relocation_validation
model_name: sentry.relocationvalidationattempt
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- integration_id
Expand All @@ -1337,13 +1435,19 @@ source: tests/sentry/backup/test_comparators.py
- project
model_name: sentry.reprocessingreport
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- environment_id
- owner
- project
model_name: sentry.rule
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- rule
Expand All @@ -1357,6 +1461,10 @@ source: tests/sentry/backup/test_comparators.py
- rule
model_name: sentry.rulefirehistory
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- until
- class: ForeignKeyComparator
fields:
- alert_rule
Expand All @@ -1365,6 +1473,9 @@ source: tests/sentry/backup/test_comparators.py
- user_id
model_name: sentry.rulesnooze
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- organization
Expand Down Expand Up @@ -1463,6 +1574,9 @@ source: tests/sentry/backup/test_comparators.py
- service_hook
model_name: sentry.servicehookproject
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- class: ForeignKeyComparator
fields:
- environment
Expand Down Expand Up @@ -1505,6 +1619,11 @@ source: tests/sentry/backup/test_comparators.py
- team_id
model_name: sentry.teamreplica
- comparators:
- class: DatetimeEqualityComparator
fields:
- date_added
- end
- start
- class: ForeignKeyComparator
fields: []
model_name: sentry.timeseriessnapshot
Expand Down
Loading

0 comments on commit b1280ef

Please sign in to comment.