Skip to content

fix(errors): surface the history-gate 402 upgrade link in SDK and CLI - #164

Merged
karlwaldman merged 3 commits into
mainfrom
fix/402-upgrade-url
Nov 15, 2026
Merged

karlwaldman merged 3 commits into
mainfrom
fix/402-upgrade-url

Conversation

@karlwaldman

Copy link
Copy Markdown
Member

Fixes #163 (code part).

The UPGRADE_REQUIRED 402 sends its link as upgrade.url; there is no top-level upgrade_url, so PaymentRequiredError.remediation_url was None. From 2026-11-16 /v1/prices/historical and /history join that gate (api#10744).

Change File
remediation_url falls back to upgrade.url oilpriceapi/exceptions.py
oilprice historical prints the upgrade link (unwrapped) and the latest-price command on 402/403 oilpriceapi/cli.py
5 tests, body copied from the API controller tests/unit/test_history_gate_402.py

Tests: new file red on origin/main (2 failed), green with fix. tests/unit 1905 passed; 24 failures are test_streaming* needing websockets, not installed locally, unrelated.

Not done: PyPI publish of 1.18.0 (release step).

🤖 Generated with Claude Code

… (api#10744)

The UPGRADE_REQUIRED 402 sends its link as upgrade.url, with no top-level
upgrade_url, so PaymentRequiredError.remediation_url was None. From
2026-11-16 /v1/prices/historical and /history join that gate.

- error_from_response falls back to upgrade.url for remediation_url
- oilprice historical prints the upgrade link (unwrapped) and the
  latest-price command that still works on a 402/403

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 23d3526f-8093-4722-a5e3-c78c1ecacc18
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A quota 402 (free_tier_quota_exceeded) also refuses /v1/prices/latest,
so the hint was false there. Show it only for UPGRADE_REQUIRED; the
upgrade link still prints for any 402/403 that sends one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@karlwaldman

karlwaldman commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Pushed 1306341: fix(cli): only claim latest prices still work for the history gate.

Finding: _print_error printed "Latest prices still work" on any 402/403. A free account over quota gets 402 free_tier_quota_exceeded on /v1/prices/latest too (production api_requests, 30 days: 7,113 such 402s from one sdk-python 1.5.0 account), so the hint would be false. Now gated on code == UPGRADE_REQUIRED; the upgrade link still prints for any 402/403. New test test_cli_quota_402_does_not_claim_latest_still_works is red on the previous head, green now; full suite 2041 passed, 68 skipped; ruff clean.

Test (Python 3.8/3.9) will still fail until #166 merges (#165). This head needs a fresh review; I authored this commit, so I am not posting a verdict.

@karlwaldman

Copy link
Copy Markdown
Member Author

Adversarial review: APPROVE.

  • Body shape checked against oilpriceapi-api origin/main V1::PricesController#require_paid_tier_for_historical: the 402 sends code: UPGRADE_REQUIRED, message, and the link only at upgrade.url; no top-level upgrade_url. The test fixture matches it.
  • Precedence: top-level remediation_url / upgrade_url / action_url still win; upgrade.url is a fallback only.
  • Red/green: reverting exceptions.py and cli.py to main makes 3 of the 6 new tests fail; on this head all 6 pass.
  • Malformed input (Python 3.8 probe): upgrade: null, upgrade: "see pricing", upgrade: {url: ""}, a list body, {}, and an HTML 402 all give remediation_url=None with no exception. A link nested under error.upgrade.url is also found. A 403 with the same body maps to PermissionDeniedError with the URL. Only gap: upgrade: {url: 123} passes the int through (the CLI would print Upgrade: 123); the API never sends that, so not blocking.
  • CLI: the "Latest prices still work" hint appears only for UPGRADE_REQUIRED, not for a quota 402. oilprice price exists. The URL is printed with markup=False, soft_wrap=True.
  • Test (Python 3.8/3.9) red is the setup-python / Ubuntu 26.04 failure fixed by ci: pin test matrix to ubuntu-24.04 (fixes 3.8/3.9 setup failure) #166 (log: version '3.8' ... was not found for Ubuntu 26.04); the tests never ran. Run locally with .[dev,cli,viz,pandas]: 3.8.20 2059 passed, 3.9 2059 passed, 3.12 2059 passed, 0 skipped. CI-equivalent .[dev] on 3.8: ruff clean, mypy clean, storefront claims ok.
  • CI coverage gap: in CI both CLI tests are SKIPPED because .[dev] has no click or rich (job 132628922930). Filed [P2] CI skips every CLI and viz test: .[dev] lacks click, rich, matplotlib #169.
  • No secrets. No display or redistribution rights claimed.

Rebase after #166 for a green 3.8/3.9 run before merging is recommended.

@karlwaldman
karlwaldman merged commit c2e11cc into main Nov 15, 2026
7 checks passed
@karlwaldman
karlwaldman deleted the fix/402-upgrade-url branch November 15, 2026 21:57
karlwaldman added a commit that referenced this pull request Nov 15, 2026
History-gate 402 upgrade link in SDK and CLI (#163, #164), small multiples
in one row (#158), lazy visualizer (#151).

Refs #163

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:elevated Elevated: auto-merges after an adversarial review APPROVE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] 402 history gate: surface upgrade link in SDK + oilprice CLI; ship 1.18.0

1 participant