feat(backend): adopt climate_ref.results.Reader for metric values#39
feat(backend): adopt climate_ref.results.Reader for metric values#39lewisjared wants to merge 2 commits into
Conversation
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.
✅ Deploy Preview for climate-ref canceled.
|
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Migrates the backend's two
/valuesendpoints off hand-rolled SQLAlchemy queries and onto the newclimate_ref.results.Readerread-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}/valuesandGET /diagnostics/{provider}/{diagnostic}/valuesnow queryapp_context.reader.values.{scalar,series}_values(...)viaMetricValueFilter+OutlierPolicy.get_readerdependency onAppContext(additive; the raw session dependency is untouched and still used by the not-yet-migrated routes).core/reader_values.pyfor CSV rendering from reader collections and CV-dimension query-param gating;MetricValueCollection.build_{scalar,series}_from_readeradapters inmodels.py.Response shapes are unchanged.
promoted_only=Falseandinclude_retracted=Trueare 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)
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.>=3.12.diagnostic.promoted_versionwas 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
mypy(strict) andruffclean.Follow-ups (later phases)
core/outliers.pyand the query half ofcore/metric_values.pyonce nothing references them.float(item.value)would raise; none in the current fixture).