Skip to content

fix(detectors): Clarify Detector status vs enabled; update code accordingly#113761

Merged
kcons merged 3 commits intomasterfrom
kcons/rectify
Apr 23, 2026
Merged

fix(detectors): Clarify Detector status vs enabled; update code accordingly#113761
kcons merged 3 commits intomasterfrom
kcons/rectify

Conversation

@kcons
Copy link
Copy Markdown
Member

@kcons kcons commented Apr 22, 2026

We've been blurring the distinction between plan disabling of Detectors and snooze disabling.
This change aims to clarify the distinction, and update existing code that cares about one or the other to only update the field they should be modifying.

Note that code and tests in getsentry also use this code, so a legacy alias in retained here, and there is another PR (https://github.com/getsentry/getsentry/pull/20011) to update the tests in that repo to still pass with this PR applied.

@kcons kcons requested review from a team as code owners April 22, 2026 22:54
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 22, 2026
@kcons kcons requested a review from ceorourke April 22, 2026 22:57
Comment thread src/sentry/workflow_engine/endpoints/validators/base/detector.py
Comment thread src/sentry/incidents/logic.py
Copy link
Copy Markdown
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

high level this makes sense, is the plan to go back and update the detector selection in processing separately?

# The detector's status - used for tracking deletion state
# The detector's status - used for tracking disabled and deletion state.
# A Detector that isn't allowed by plan or is effectively temporarily
# deleted for some other reason should have status=ObjectStatus.DISABLED.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we update the get_queryset to automatically filter out the disabled detectors? these seem like they're not recoverable directly by a user, but would require some other action before being re-enabled.

that or we should filter detectors that are disabled in process_data_sources -- i'd lean more towards the manager so it's consistent, even outside of our primary use cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm unsure. At present, this distinction is only really relevant to Metric Detectors, and we already unsubscribe those on plan change and filtering the disallowed ones in the APIs, so the difference behaviorally isn't substantial.
But, filtering out disabled detectors by default makes all of that much cheaper, because we only really have to evaluate it once and cache it, so I do want to go that way.
I'm thinking of going further as a follow-up; for now, I'm trying to just correct current behavioral patterns enough to fix the getsentry-side processing.

But it does make sense to make more of the general code aware of this by default; we want new uses of this status work automatically.

# A Detector that isn't allowed by plan or is effectively temporarily
# deleted for some other reason should have status=ObjectStatus.DISABLED.
# The 'enabled' field is for user-applied deactivation like snoozes.
status = models.SmallIntegerField(db_default=ObjectStatus.ACTIVE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉 - glad we can reuse this field instead of adding a new one!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

Backend Test Failures

Failures on b5df693 in this run:

tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py::OrganizationDetectorDetailsPutTest::test_disable_detectorlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py:551: in test_disable_detector
    assert detector.status == ObjectStatus.DISABLED
E   assert 0 == 1
E    +  where 0 = <Detector at 0x7fcd36a7b520: id=729>.status
E    +  and   1 = ObjectStatus.DISABLED
tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py::OrganizationDetectorDetailsPutTest::test_enable_detectorlog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py:570: in test_enable_detector
    assert detector.status == ObjectStatus.ACTIVE
E   assert 1 == 0
E    +  where 1 = <Detector at 0x7f40e58e3040: id=832>.status
E    +  and   0 = ObjectStatus.ACTIVE

@kcons
Copy link
Copy Markdown
Member Author

kcons commented Apr 22, 2026

getsentry side, required for cross-repo tests to pass: https://github.com/getsentry/getsentry/pull/20011

@kcons kcons merged commit 5e55397 into master Apr 23, 2026
77 checks passed
@kcons kcons deleted the kcons/rectify branch April 23, 2026 00:31
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.

3 participants