Skip to content

feat(backend): adopt climate_ref.results.Reader for metric values#39

Open
lewisjared wants to merge 2 commits into
mainfrom
feat/adopt-results-reader
Open

feat(backend): adopt climate_ref.results.Reader for metric values#39
lewisjared wants to merge 2 commits into
mainfrom
feat/adopt-results-reader

Conversation

@lewisjared

Copy link
Copy Markdown
Contributor

Summary

Migrates the backend's two /values endpoints off hand-rolled SQLAlchemy queries and onto the new climate_ref.results.Reader read-layer facade — the consumer that read layer was explicitly designed for. This is the first, keystone slice of a phased adoption (plan tracked separately); it targets the biggest duplication: metric-value filtering, source-id-aware IQR outlier detection, facet collection, and the load-all-then-paginate rule now all live upstream.

  • GET /executions/{group_id}/values and GET /diagnostics/{provider}/{diagnostic}/values now query app_context.reader.values.{scalar,series}_values(...) via MetricValueFilter + OutlierPolicy.
  • New get_reader dependency on AppContext (additive; the raw session dependency is untouched and still used by the not-yet-migrated routes).
  • New core/reader_values.py for CSV rendering from reader collections and CV-dimension query-param gating; MetricValueCollection.build_{scalar,series}_from_reader adapters in models.py.

Response shapes are unchanged. promoted_only=False and include_retracted=True are set explicitly to preserve the previous unfiltered behaviour rather than adopt the reader's stricter defaults — so this is behaviour-preserving, which the existing route tests confirm.

Dependency / environment changes (please review)

  • climate-ref is pinned to unreleased main (rev=67f1580) because the read layer is merged but not yet in a tagged release. Same pattern as the earlier metric-value-contract pin; swap to a tagged release (>=0.16) once one is published.
  • Python floor moves 3.11 → 3.12, because climate-ref 0.15 requires >=3.12.
  • The decimated test-fixture DB is migrated to the 0.15 schema (it was 4 alembic revisions behind; diagnostic.promoted_version was missing). This was done with climate-ref's own migrations — the same path a deployed 0.13-era database will take. Deployed REF databases must be alembic-migrated to head before a reader-based backend can read them.

Testing

  • Full backend suite green: 185 passed, 1 xfailed (unchanged from the pre-migration baseline), against the git-pinned climate-ref.
  • mypy (strict) and ruff clean.

Follow-ups (later phases)

  • Migrate the executions/diagnostics list routes, datasets, and artifacts endpoints.
  • Delete the now-dead core/outliers.py and the query half of core/metric_values.py once nothing references them.
  • Harden the scalar adapter against null-valued scalars (float(item.value) would raise; none in the current fixture).

Route the two /values endpoints (executions and diagnostics) through the new
climate_ref.results read-layer facade instead of hand-rolled SQLAlchemy
queries, and add a get_reader dependency on AppContext for the migration.

- Query scalar/series values via MetricValueFilter + OutlierPolicy, with a
  new core/reader_values.py helper for CSV rendering and dimension-param
  gating. Response shapes are preserved: promoted_only=False and
  include_retracted=True keep the previous unfiltered behaviour rather than
  taking the reader's stricter defaults.
- Pin climate-ref to unreleased main for the read layer and relax the
  constraint to >=0.15,<0.16. climate-ref 0.15 requires Python >=3.12, so the
  backend floor moves 3.11 -> 3.12.
- Migrate the decimated test-fixture database to the 0.15 schema
  (adds diagnostic.promoted_version and later revisions); deployed databases
  will need the same alembic upgrade.
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for climate-ref canceled.

Name Link
🔨 Latest commit ca09520
🔍 Latest deploy log https://app.netlify.com/projects/climate-ref/deploys/6a4c41a98755a40009052705

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@lewisjared, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: edf41615-7b59-4168-9519-e1dbe9c67258

📥 Commits

Reviewing files that changed from the base of the PR and between e501f1d and ca09520.

⛔ Files ignored due to path filters (2)
  • backend/tests/test-data/tests.integration.test_cmip7_aft/test_solve_cmip7_aft/db/climate_ref.db is excluded by !**/*.db
  • backend/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • backend/pyproject.toml
  • backend/src/ref_backend/api/deps.py
  • backend/src/ref_backend/api/routes/diagnostics.py
  • backend/src/ref_backend/api/routes/executions.py
  • backend/src/ref_backend/core/reader_values.py
  • backend/src/ref_backend/models.py
  • changelog/39.breaking.md
  • changelog/39.trivial.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/adopt-results-reader

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant