Skip to content

fix(db): add missing offering columns to GetActivePurchaseHistory SELECT (production-down) - #1472

Merged
cristim merged 1 commit into
mainfrom
fix/active-purchase-history-column-mismatch
Jul 20, 2026
Merged

fix(db): add missing offering columns to GetActivePurchaseHistory SELECT (production-down)#1472
cristim merged 1 commit into
mainfrom
fix/active-purchase-history-column-mismatch

Conversation

@cristim

@cristim cristim commented Jul 19, 2026

Copy link
Copy Markdown
Member

CRITICAL — dashboard KPIs, inventory endpoints, and analytics collector broken on real Postgres

Found by the adversarial (Fable) review sweep of recently-merged PRs.

GetActivePurchaseHistory SELECTed 21 columns but shares scanPurchaseHistoryRow, which scans 24 destinations (offering_class, listing_id, listing_state were added by #808). pgx/v5 Rows.Scan requires field count == destination count, so every real-Postgres call to this query fails:
number of field descriptions must equal number of destinations, got 21 and 24.

Impact

  • Dashboard commitment KPIs render 0 active commitments / $0 committed monthly / $0 YTD (fetchCommitmentPurchases swallows the error → fabricated $0 on a money path).
  • GET /api/inventory/commitments and /api/inventory/coverage return errors.
  • The analytics collector's Collect fails every run.

Root cause

#808 (marketplace, closes #292) added the three columns to the scanner and to GetPurchaseHistory / GetAllPurchaseHistory / GetPurchaseHistoryFiltered but missed GetActivePurchaseHistory. Same defect class as #1221 (17-vs-21).

Fix

Append offering_class, listing_id, listing_state so the column list is identical to the other purchase-history queries and matches the scanner (verified: 24 == 24, identical to GetAllPurchaseHistory). Updated the pgxmock regex to pin the corrected list.

Verification

  • Column lists of GetActivePurchaseHistory and GetAllPurchaseHistory are now identical (24 each).
  • go build, go vet, full internal/config suite green.
  • Note: pgxmock fabricates result columns so it can't reproduce the field-count mismatch; a shared "emitted SELECT columns == purchaseHistoryCols" assertion across all purchase-history queries is a worthwhile follow-up (filed mentally as test-infra debt).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed purchase history retrieval failures caused by missing marketplace details in query results.
    • Dashboard and analytics views now correctly load purchase records with offering class, listing ID, and listing status.

GetActivePurchaseHistory SELECTed 21 columns but shares scanPurchaseHistoryRow,
which scans 24 destinations (offering_class, listing_id, listing_state were
added by #808). pgx/v5 Rows.Scan requires field count == destination count, so
every real-Postgres call to this query failed with "number of field
descriptions must equal number of destinations, got 21 and 24".

Impact (all broken on real Postgres, silently in some paths):
- dashboard commitment KPIs (fetchCommitmentPurchases swallows the error and
  renders 0 active commitments / $0 committed monthly / $0 YTD),
- GET /api/inventory/commitments and /api/inventory/coverage (return errors),
- the analytics collector's Collect (fails every run).

#808 (marketplace) added the three columns to the scanner and to
GetPurchaseHistory / GetAllPurchaseHistory / GetPurchaseHistoryFiltered but
missed GetActivePurchaseHistory. This is the same class of defect #1221 fixed
for the 17-vs-21 case.

Fix: append offering_class, listing_id, listing_state so the column list is
identical to the other purchase-history queries and matches the scanner.
Update the pgxmock regex to pin the corrected column list so a future drop of
these columns fails the test.

Note: pgxmock cannot reproduce the field-count mismatch (it fabricates result
columns), so the regression is only guarded via the SQL-text regex here; a
shared "emitted SELECT column list == purchaseHistoryCols" assertion across all
purchase-history queries is a worthwhile follow-up.

Found by the adversarial (Fable) review sweep of recently-merged PRs.
@cristim cristim added triaged Item has been triaged priority/p0 Drop everything; same-day fix severity/critical Major harm when it happens urgency/now Drop other things impact/all-users Affects every user effort/xs Trivial / one-liner type/bug Defect labels Jul 19, 2026
@cristim

cristim commented Jul 19, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 125366bf-992e-4fd2-8eda-7bf10992dfda

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

GetActivePurchaseHistory now selects offering_class, listing_id, and listing_state, matching the shared purchase-history scan destinations. The corresponding pgxmock expectation was updated to validate the expanded SQL projection.

Changes

Purchase history projection

Layer / File(s) Summary
Align projection and test expectation
internal/config/store_postgres.go, internal/config/store_postgres_pgxmock_test.go
The active purchase history query includes the three marketplace columns required by row scanning, and the unscoped pgxmock test expects those fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: adding missing offering columns to GetActivePurchaseHistory's SELECT list.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/active-purchase-history-column-mismatch

Comment @coderabbitai help to get the list of available commands.

@cristim
cristim merged commit f7a4fbd into main Jul 20, 2026
19 checks passed
@cristim
cristim deleted the fix/active-purchase-history-column-mismatch branch July 27, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/all-users Affects every user priority/p0 Drop everything; same-day fix severity/critical Major harm when it happens triaged Item has been triaged type/bug Defect urgency/now Drop other things

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(history): Sell-on-Marketplace button for Standard RIs (CreateReservedInstancesListing) with status polling + sell-{any,own} RBAC

1 participant