Skip to content

Commit

Permalink
Add test that makees me realize the solution doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
ceorourke committed Jan 31, 2025
1 parent 5e28ceb commit f6e9c87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sentry/deletions/defaults/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get_child_relations(self, instance: Detector) -> list[BaseRelation]:
data_sources = DataSource.objects.filter(detector=instance.id)
delete = True

# this doesn't work if a data source is also connected to a different detector that's not being deleted
for data_source in data_sources:
for detector in data_source.detectors.all():
if detector.id != instance.id:
Expand Down
21 changes: 21 additions & 0 deletions tests/sentry/deletions/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,24 @@ def test_data_source_not_deleted(self):
assert not DataCondition.objects.filter(id=self.data_condition.id).exists()
assert DataSource.objects.filter(id=self.data_source.id).exists()
assert DataSourceDetector.objects.filter(id=data_source_detector_2.id).exists()

def test_multiple_data_sources(self):
"""
Test that if we have multiple data sources where one is connected to another Detector but the other one isn't, we only delete one
"""
data_condition_group = self.create_data_condition_group()
self.create_data_condition(condition_group=data_condition_group)
detector = self.create_detector(
project_id=self.project.id,
name="Testy Detector",
type=MetricAlertFire.slug,
workflow_condition_group=data_condition_group,
)
data_source_2 = self.create_data_source(organization=self.organization)

# multiple data sources for one detector
self.create_data_source_detector(data_source=data_source_2, detector=self.detector)
# but the data source is also connected to a different detector
self.create_data_source_detector(data_source=data_source_2, detector=detector)
assert not DataSource.objects.filter(id=self.data_source.id).exists()
assert DataSource.objects.filter(id=data_source_2.id).exists()

0 comments on commit f6e9c87

Please sign in to comment.