Skip to content

fix(snapshots): Fix staff auth blocking initial size comparison selection#112739

Merged
NicoHinderling merged 2 commits intomasterfrom
fix/size-comparison-staff-auth-flow
Apr 13, 2026
Merged

fix(snapshots): Fix staff auth blocking initial size comparison selection#112739
NicoHinderling merged 2 commits intomasterfrom
fix/size-comparison-staff-auth-flow

Conversation

@NicoHinderling
Copy link
Copy Markdown
Contributor

Summary

The size comparison POST endpoint was applying staff re-auth checks whenever existing comparisons were found, regardless of context. This caused staff users to hit a 403 StaffRequired error on the build selection page when selecting a pair that already had comparison results.

Fix: Use a ?rerun=true query parameter to distinguish the "Rerun Comparison" admin flow from normal comparison triggers.

Logic paths

Scenario ?rerun Existing state Behavior
Build selection page no no comparison exists Creates new comparison
Build selection page no SUCCESS/PENDING exists Returns status: "exists", navigates to results
Build selection page no all FAILED Deletes failed, re-creates (retry without staff gate)
Retry button (failed comparison) no all FAILED Deletes failed, re-creates (retry without staff gate)
"Rerun Comparison" admin button yes active superuser/staff Deletes and re-runs
"Rerun Comparison" admin button yes is_staff but not re-authed StaffRequired (triggers re-auth modal)
"Rerun Comparison" admin button yes non-staff 403

Files changed

  • Backend: project_preprod_size_analysis_compare.py — branching logic based on ?rerun query param
  • Frontend: buildComparison.tsx — rerun mutation now sends ?rerun=true

…tion

Previously, the size comparison POST endpoint applied staff re-auth
checks whenever existing comparisons were found, regardless of whether
the user was selecting a build pair or explicitly re-running. This
caused staff users to hit a 403 StaffRequired error on the build
selection page.

Split the behavior using a ?rerun=true query parameter:
- Without ?rerun: returns existing comparisons or allows retry of
  all-failed comparisons without staff auth
- With ?rerun=true: staff-gated delete and re-run for the admin
  "Rerun Comparison" button

Co-Authored-By: Claude <noreply@anthropic.com>
@NicoHinderling NicoHinderling requested a review from a team as a code owner April 10, 2026 20:53
@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 8f81284 in this run:

tests/sentry/preprod/api/endpoints/size_analysis/test_project_preprod_size_analysis_compare.py::ProjectPreprodSizeAnalysisCompareTest::test_post_comparison_existing_failed_comparisonlog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/preprod/api/endpoints/size_analysis/test_project_preprod_size_analysis_compare.py:619: in test_post_comparison_existing_failed_comparison
    assert data["status"] == "exists"
E   AssertionError: assert 'created' == 'exists'
E     
E     - exists
E     + created

… flow

Update test_post_comparison_existing_failed_comparison to expect
auto-retry behavior (status=created) when all comparisons are failed.
Add tests for the rerun=true staff auth flow: active staff succeeds,
non-staff gets 403, inactive staff gets StaffRequired.
@NicoHinderling NicoHinderling merged commit 37a7bb3 into master Apr 13, 2026
60 checks passed
@NicoHinderling NicoHinderling deleted the fix/size-comparison-staff-auth-flow branch April 13, 2026 16:13
wedamija pushed a commit that referenced this pull request Apr 13, 2026
…tion (#112739)

## Summary

The size comparison POST endpoint was applying staff re-auth checks
whenever existing comparisons were found, regardless of context. This
caused staff users to hit a `403 StaffRequired` error on the build
selection page when selecting a pair that already had comparison
results.

**Fix:** Use a `?rerun=true` query parameter to distinguish the "Rerun
Comparison" admin flow from normal comparison triggers.

### Logic paths

| Scenario | `?rerun` | Existing state | Behavior |
|---|---|---|---|
| Build selection page | no | no comparison exists | Creates new
comparison |
| Build selection page | no | SUCCESS/PENDING exists | Returns `status:
"exists"`, navigates to results |
| Build selection page | no | all FAILED | Deletes failed, re-creates
(retry without staff gate) |
| Retry button (failed comparison) | no | all FAILED | Deletes failed,
re-creates (retry without staff gate) |
| "Rerun Comparison" admin button | yes | active superuser/staff |
Deletes and re-runs |
| "Rerun Comparison" admin button | yes | `is_staff` but not re-authed |
`StaffRequired` (triggers re-auth modal) |
| "Rerun Comparison" admin button | yes | non-staff | 403 |

### Files changed
- **Backend**: `project_preprod_size_analysis_compare.py` — branching
logic based on `?rerun` query param
- **Frontend**: `buildComparison.tsx` — rerun mutation now sends
`?rerun=true`

---------

Co-authored-by: Claude <noreply@anthropic.com>
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 Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants