Skip to content

Commit cb15e1a

Browse files
committed
make it correct
1 parent 32e7022 commit cb15e1a

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/sentry/workflow_engine/models/data_source.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,11 @@ def normalize_before_relocation_import(
7575
old_source_id = int(self.source_id)
7676
new_source_id = pk_map.get_pk(model_name, old_source_id)
7777

78-
if new_source_id is not None:
79-
self.source_id = str(new_source_id)
80-
else:
81-
# Referenced model not in pk_map. This may be correct (reset_pks=False) or broken
82-
# (reset_pks=True but referenced model was filtered out or failed to import).
83-
logger.warning(
84-
"DataSource source_id not remapped - referenced model not in pk_map",
85-
extra={
86-
"data_source_id": old_pk,
87-
"type": self.type,
88-
"source_id": old_source_id,
89-
"model": str(model_name),
90-
},
91-
)
78+
if new_source_id is None:
79+
# Referenced model not in pk_map - the source was filtered out or failed to import.
80+
return None
81+
82+
self.source_id = str(new_source_id)
9283
except Exception:
9384
logger.exception(
9485
"DataSource.normalize_before_relocation_import failed",

tests/sentry/workflow_engine/models/test_data_source.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def test_data_source_valid_type(self) -> None:
2424
assert data_source.type == "test"
2525

2626
def test_normalize_before_relocation_import(self) -> None:
27-
"""Test that normalize_before_relocation_import correctly maps source_id"""
2827
monitor = self.create_monitor(project=self.project)
2928
data_source = self.create_data_source(
3029
type=DATA_SOURCE_CRON_MONITOR,
@@ -63,16 +62,13 @@ def test_normalize_before_relocation_import(self) -> None:
6362
assert data_source.pk is None
6463

6564
def test_normalize_before_relocation_import_missing_source(self) -> None:
66-
"""Test that normalize_before_relocation_import succeeds but doesn't update source_id if mapping not found"""
6765
monitor = self.create_monitor(project=self.project)
6866
data_source = self.create_data_source(
6967
type=DATA_SOURCE_CRON_MONITOR,
7068
source_id=str(monitor.id),
7169
organization_id=self.organization.id,
7270
)
7371

74-
old_source_id = data_source.source_id
75-
old_data_source_id = data_source.id
7672
old_org_id = data_source.organization_id
7773

7874
# Create a PrimaryKeyMap without the monitor mapping
@@ -88,7 +84,5 @@ def test_normalize_before_relocation_import_missing_source(self) -> None:
8884
pk_map, ImportScope.Organization, ImportFlags()
8985
)
9086

91-
# Should succeed but leave source_id unchanged
92-
assert result == old_data_source_id
93-
assert data_source.source_id == old_source_id
94-
assert data_source.pk is None
87+
# Should return None when the referenced source is not in pk_map
88+
assert result is None

0 commit comments

Comments
 (0)