Skip to content

ref(preprod): Extract shared snapshot status derivation for list and detail endpoints#115604

Open
mtopo27 wants to merge 4 commits into
masterfrom
mtopo27/eme-1149-shared-snapshot-status-derivation
Open

ref(preprod): Extract shared snapshot status derivation for list and detail endpoints#115604
mtopo27 wants to merge 4 commits into
masterfrom
mtopo27/eme-1149-shared-snapshot-status-derivation

Conversation

@mtopo27
Copy link
Copy Markdown
Contributor

@mtopo27 mtopo27 commented May 14, 2026

The snapshot list and detail API endpoints independently derived comparison_state and approval_status with duplicated logic that had diverged — different casing (UPPER vs lower), missing grace period / no_base_build on the detail endpoint, no comparison_error_message on detail, and auto_approved represented as a string vs boolean. This extracts the derivation into a single shared function and adds flat status fields to the detail response so both endpoints speak the same language.

Shared derivation function

derive_snapshot_status() in snapshot_status.py takes pre-fetched data (latest comparison, latest approval, grace period inputs) and returns comparison_state, approval_status, and comparison_error_message. Both to_snapshot_comparison_info() (list) and the detail endpoint's get() now delegate to it. No ORM queries in the shared function — callers assemble input from their own data.

Flat fields on the detail response

SnapshotDetailsApiResponse gains four additive fields: comparison_state, approval_status, comparison_error_message, and approvers (hoisted from approval_info). Existing split fields (comparison_type, comparison_run_info, approval_info) are unchanged — deprecation is a separate effort. The detail endpoint also gains grace period / no_base_build logic it was previously missing, closing a behavioral gap with the list API.

Refs EME-1149

…detail endpoints

Both the snapshot list and detail API endpoints independently derived
comparison_state and approval_status with duplicated logic that had
diverged (casing, grace period handling, auto_approved representation).
This extracts a shared derive_snapshot_status() function and adds flat
comparison_state, approval_status, comparison_error_message, and
approvers fields to the detail response.

Refs EME-1149
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 14, 2026

EME-1149

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 14, 2026
…tus type aliases

Reduce three separate PreprodSnapshotComparison queries in the detail
endpoint to a single fetch, deriving latest_comparison, successful
comparison, and pending/failed state from the same queryset. Extract
ComparisonStateLiteral and ApprovalStatusLiteral type aliases to
eliminate duplicate Literal definitions across models. Trim redundant
unit tests in test_snapshot_status.
@mtopo27 mtopo27 marked this pull request as ready for review May 14, 2026 21:57
@mtopo27 mtopo27 requested a review from a team as a code owner May 14, 2026 21:57
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