Skip to content

fix(cleanup): Move partition validation before environment setup#108404

Open
joshuarli wants to merge 1 commit intomasterfrom
fix/cleanup-partition-validation-env-pollution
Open

fix(cleanup): Move partition validation before environment setup#108404
joshuarli wants to merge 1 commit intomasterfrom
fix/cleanup-partition-validation-env-pollution

Conversation

@joshuarli
Copy link
Member

Summary

Fixes test pollution where PartitionValidationTest tests in the cleanup command would leave os.environ["_SENTRY_CLEANUP"] set, causing subsequent tests to fail.

Reproduction:

pytest --reuse-db tests/sentry/runner/commands/test_cleanup.py::PartitionValidationTest::test_partition_bucket_exceeds_total tests/sentry/deletions/test_project.py::DeleteProjectTest::test_delete_error_events

Root cause: _cleanup() called _validate_and_setup_environment() (which sets _SENTRY_CLEANUP env var) before partition flag validation. When validation raised a ClickException, the env var persisted and caused group deletion to skip ErrorEventsDeletionTask, so error events were never deleted.

Fix: Move partition validation before _validate_and_setup_environment() so invalid input is rejected before any environment modifications.

…revent test pollution

Partition flag validation in `_cleanup()` was happening after
`_validate_and_setup_environment()`, which sets `os.environ["_SENTRY_CLEANUP"]`.
When validation raised a ClickException, the env var was left set, causing
subsequent tests to skip error event deletion (the env var makes group deletion
skip `ErrorEventsDeletionTask`).
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 17, 2026
@joshuarli joshuarli requested a review from rbro112 February 17, 2026 22:53
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 test-pollution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant