refactor: unify facet filter parsing across CLI commands#613
Merged
lewisjared merged 2 commits intomainfrom Apr 10, 2026
Merged
refactor: unify facet filter parsing across CLI commands#613lewisjared merged 2 commits intomainfrom
lewisjared merged 2 commits intomainfrom
Conversation
Consolidate three inconsistent filter parsing implementations into a single `parse_facet_filters` returning `dict[str, list[str]]` with multi-value OR semantics. Previously, `--filter key=val key=val2` in executions silently overwrote the first value; it now correctly returns results matching either value, consistent with `--dataset-filter` in `datasets list` and `solve`. - `cli/_utils.py`: `parse_facet_filters` returns multi-value dict - `cli/datasets.py`, `cli/solve.py`: replace inline parsing with shared function - `cli/executions.py`: update `ListGroupsFilterOptions.facets` type - `models/execution.py`: update `_filter_executions_by_facets` signature, extract `_selectors_match_facet` helper - Fix wrong docstring on `datasets list-columns`
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the CLI facet/dataset filter handling to use a single shared parser with consistent “AND across keys, OR within key” semantics, eliminating divergent behavior across commands.
Changes:
- Updated
parse_facet_filtersto returndict[str, list[str]]and collect repeated keys as multi-value OR filters. - Switched
datasets list,solve, andexecutions list-groups/delete-groupsto use the shared parser; updated execution-group facet filtering to support multi-value filters. - Updated/added unit tests and added a changelog entry; corrected the
datasets list-columnsdocstring.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/climate-ref/src/climate_ref/cli/_utils.py | Changes parse_facet_filters to return multi-value lists and updates validation/errors. |
| packages/climate-ref/src/climate_ref/cli/datasets.py | Replaces inline dataset-filter parsing with shared parse_facet_filters; fixes list_columns docstring. |
| packages/climate-ref/src/climate_ref/cli/solve.py | Uses shared parse_facet_filters for --dataset-filter and maps parsing errors to BadParameter. |
| packages/climate-ref/src/climate_ref/cli/executions.py | Updates facet filter typing and “no results” messaging for multi-value facet filters. |
| packages/climate-ref/src/climate_ref/models/execution.py | Adds helper and updates facet filtering to support OR-within-key semantics. |
| packages/climate-ref/tests/unit/cli/test_utils.py | Updates expectations and adds tests for multi-value and dotted keys. |
| packages/climate-ref/tests/unit/cli/test_solve.py | Updates error-message assertions to match new parsing errors. |
| packages/climate-ref/tests/unit/cli/test_executions.py | Updates tests to validate OR semantics for repeated facet keys in executions filtering. |
| changelog/613.improvement.md | Documents the user-visible change to executions --filter behavior. |
Comments suppressed due to low confidence (2)
packages/climate-ref/src/climate_ref/cli/_utils.py:80
- The ValueError message here suggests
dataset_type.key=valueis a supported/expected format. That’s true forexecutions --filter, butsolve --dataset-filter/datasets list --dataset-filterdon’t support dataset-type scoping (those keys won’t match catalog columns and may be ignored or rejected later). Consider tightening this message to justkey=value, or explicitly clarifying thatdataset_type.key=valueis only supported for execution facet filters so users aren’t misled.
if "=" not in filter_str:
raise ValueError(
f"Invalid filter format: '{filter_str}'. "
f"Expected format: 'key=value' or 'dataset_type.key=value' "
f"(e.g., 'source_id=GFDL-ESM4' or 'cmip6.source_id=GFDL-ESM4')"
)
packages/climate-ref/src/climate_ref/cli/solve.py:99
- Now that
--dataset-filteruses the sharedparse_facet_filters, keys containing a dot (e.g.cmip6.source_id=...) will parse successfully. Howeverapply_dataset_filters()only matches literal column names and skips unknown facets, so dotted keys will silently have no effect insolve. Consider validatingparsed_dataset_filtershere (e.g., reject keys containing '.') or normalizing them so dataset filters don’t become accidental no-ops.
try:
parsed_dataset_filters = parse_facet_filters(dataset_filter) or None
except ValueError as e:
raise typer.BadParameter(str(e), param_hint="--dataset-filter")
filters = SolveFilterOptions(
diagnostic=diagnostic,
provider=provider,
dataset=parsed_dataset_filters,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Consolidate three inconsistent filter parsing implementations into a single
parse_facet_filtersreturningdict[str, list[str]]with multi-value OR semantics.Problem: The CLI had three different filter parsing paths with different behavior:
cli/_utils.py:parse_facet_filtersreturneddict[str, str]— duplicate keys silently overwrote with a warningcli/datasets.pyhad inline parsing returningdict[str, list[str]]— multi-value OR supportcli/solve.pyduplicated the same inline parsing fromdatasets.pyThis meant
ref executions list-groups --filter source_id=A --filter source_id=Bonly matched B (overwrite), whileref datasets list --dataset-filter source_id=A --dataset-filter source_id=Bcorrectly matched A or B.Solution:
parse_facet_filtersnow returnsdict[str, list[str]]with multi-value OR semanticsdatasets list,solve,executions list-groups/delete-groups) use the shared function_filter_executions_by_facetsandget_execution_group_and_latest_filteredupdated to accept multi-value filters_selectors_match_facethelper to keep complexity under ruff limitsdatasets list-columns(was copy-pasted from config command)Checklist
Please confirm that this pull request has done the following:
changelog/