fix(crons): Sync detector name when monitor name is updated via API#116349
Open
wedamija wants to merge 1 commit into
Open
fix(crons): Sync detector name when monitor name is updated via API#116349wedamija wants to merge 1 commit into
wedamija wants to merge 1 commit into
Conversation
When a monitor's name is updated through the API, the associated Detector's name was not being synced. The new crons UI reads detector.name for the page title, so users saw the stale slug-based name even after updating via API. Fixes #116095
8e1ea6b to
c34afdd
Compare
Comment on lines
515
to
+521
| ) | ||
|
|
||
| if "name" in params and not self.context.get("from_detector_flow"): | ||
| detector = get_detector_for_monitor(instance) | ||
| if detector is not None: | ||
| detector.update(name=params["name"]) | ||
|
|
Contributor
There was a problem hiding this comment.
Bug: The database updates for a monitor and its associated detector are not atomic. A failure in the second update can leave their names out of sync.
Severity: LOW
Suggested Fix
Wrap the two database update calls, instance.update(**params) and detector.update(name=params["name"]), within a transaction.atomic() block. This will ensure that both operations succeed or fail together, maintaining data consistency.
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/monitors/validators.py#L515-L521
Potential issue: The monitor update logic performs two separate database operations: one
to update the monitor instance and another to update its associated `CronDetector`.
These operations are not wrapped in a transaction. If the first update succeeds but the
second one fails (e.g., due to a database connection error), the system will enter an
inconsistent state. The monitor will have its name updated, while the associated
detector will retain its old name, leading to a data discrepancy.
Did we get this right? 👍 / 👎 to inform future reviews.
evanpurkhiser
approved these changes
May 29, 2026
| data=instance.get_audit_log_data(), | ||
| ) | ||
|
|
||
| if "name" in params and not self.context.get("from_detector_flow"): |
Member
There was a problem hiding this comment.
Is this the only thing we need to keep in sync?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a monitor's name is updated through the API, the associated Detector's name was not being synced. The new crons UI reads detector.name for the page title, so users saw the stale slug-based name even after updating via API.
Fixes #116095