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.
It doesn't appear possible to tell the difference from an id lookup failure and cases where we run without resetting keys, so this is a bit more lax than would be ideal, but it's far better than the current behavior.

@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
Comment on lines +92 to +97
except Exception:
logger.exception(
"DataSource.normalize_before_relocation_import failed",
extra={"data_source_id": old_pk, "type": self.type, "source_id": self.source_id},
)
return None
Copy link

Choose a reason for hiding this comment

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

Bug: The except Exception block returns None, causing entire DataSource import to be skipped on error, contradicting intended lax behavior.
Severity: HIGH | Confidence: 0.95

🔍 Detailed Analysis

When an exception occurs within the normalize_before_relocation_import method, such as int(self.source_id) failing due to malformed source_id data, the broad except Exception block at lines 92-97 returns None. This causes the entire DataSource record to be skipped during import, which contradicts the intended behavior of allowing the import to proceed, logging the issue, and leaving source_id unmapped.

💡 Suggested Fix

Modify the except Exception block in normalize_before_relocation_import to return old_pk instead of None. This ensures that DataSource records are not entirely skipped during import when an unexpected error occurs, aligning with the intended behavior of allowing partial imports and logging issues.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/workflow_engine/models/data_source.py#L92-L97

Potential issue: When an exception occurs within the
`normalize_before_relocation_import` method, such as `int(self.source_id)` failing due
to malformed `source_id` data, the broad `except Exception` block at lines 92-97 returns
`None`. This causes the entire `DataSource` record to be skipped during import, which
contradicts the intended behavior of allowing the import to proceed, logging the issue,
and leaving `source_id` unmapped.

Did we get this right? 👍 / 👎 to inform future reviews.

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 91.48936% 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.80%   +0.21%     
===========================================
  Files        8937      8943       +6     
  Lines      391228    391658     +430     
  Branches    24887     24887              
===========================================
+ Hits       315277    316474    +1197     
+ Misses      75581     74814     -767     
  Partials      370       370              

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.

2 participants