Skip to content

fix: derive branded_variable when loading CMIP7 catalog from DB#712

Merged
lewisjared merged 3 commits into
mainfrom
fix/cmip7-branded-variable
Jun 4, 2026
Merged

fix: derive branded_variable when loading CMIP7 catalog from DB#712
lewisjared merged 3 commits into
mainfrom
fix/cmip7-branded-variable

Conversation

@lewisjared
Copy link
Copy Markdown
Contributor

@lewisjared lewisjared commented Jun 4, 2026

Description

Fixes #687.

CMIP7's branded_variable ({variable_id}_{branding_suffix}) is computed at parse time but never stored as a database column. A catalog loaded from the database via load_catalog was therefore missing it, and the solver raised KeyError: 'branded_variable' when applying CMIP7 data requirement filters.

It cannot simply be added to dataset_specific_metadata, because that tuple feeds the model constructor in register_dataset and branded_variable is a read-only hybrid property (no setter). Instead it is now reconstructed on load:

  • Added an overridable _add_derived_columns() hook on DatasetAdapter, called in load_catalog (including the empty-catalog path). Base implementation is a no-op.
  • CMIP7DatasetAdapter overrides it to reconstruct branded_variable; _enrich_parsed_catalog now reuses the same hook so parse-time and load-time derivation stay identical.

Why the tests missed it

The round-trip test existed and was parameterised over CMIP6/CMIP7, but CMIP7 listed branded_variable in non_roundtrip_columns, dropping it from the comparison. Other CMIP7 tests only exercised find_local_datasets (the raw catalog, which already adds the column), never the DB-load path the solver uses.

Checklist

Please confirm that this pull request has done the following:

  • Tests added
  • Documentation added (where applicable)
  • Changelog item added to changelog/

branded_variable (variable_id + "_" + branding_suffix) is computed at
parse time but never stored as a DB column, so a catalog loaded from the
database was missing it. The solver then raised KeyError: 'branded_variable'
when applying CMIP7 data requirement filters (issue #687).

Add an overridable _add_derived_columns() hook on DatasetAdapter, called
in load_catalog (including the empty-catalog path), and override it in
CMIP7DatasetAdapter to reconstruct branded_variable. _enrich_parsed_catalog
now reuses the same hook.

Strengthen round-trip coverage for both adapters: remove branded_variable
from CMIP7 non_roundtrip_columns so test_round_trip verifies it survives
the DB round-trip, and add test_derived_columns_survive_round_trip.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...kages/climate-ref/src/climate_ref/datasets/base.py 83.33% 1 Missing and 1 partial ⚠️
Flag Coverage Δ
core 93.12% <92.85%> (+0.02%) ⬆️
providers 91.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ages/climate-ref/src/climate_ref/datasets/cmip7.py 95.06% <100.00%> (+3.88%) ⬆️
...kages/climate-ref/src/climate_ref/datasets/base.py 97.66% <83.33%> (-1.10%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Make derived (computed-on-load) columns a first-class adapter concept so the
catalog round-trip contract is enforced in one place rather than duplicated in
test config.
@lewisjared lewisjared force-pushed the fix/cmip7-branded-variable branch from 9f4a4ea to dfee0e3 Compare June 4, 2026 01:59
@lewisjared lewisjared merged commit a1ffb0e into main Jun 4, 2026
26 checks passed
@lewisjared lewisjared deleted the fix/cmip7-branded-variable branch June 4, 2026 03:18
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.

Missing ingestion of branded_variable for CMIP7 datasets?

1 participant