fix(presets): reject falsy non-mapping catalog config shapes - #4320
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(presets): reject falsy non-mapping catalog config shapes#4320Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
`PresetCatalog._load_catalog_config` had two "shape check runs after
an emptiness check" bugs, both masking a corrupted preset-catalogs.yml
as an empty/no-op config instead of raising:
- Top level: `yaml.safe_load(...) or {}` coerced a FALSY non-mapping
document (`[]`, `false`, `0`, `''`) to `{}` before the
`isinstance(data, dict)` guard ran, so it was silently treated as
"no config" — while a TRUTHY non-mapping (a bare string) already
raised "expected a mapping at root".
- One level down: `catalogs_data = data.get("catalogs", [])` followed
by `if not catalogs_data: return None` ran the emptiness check
*before* the `isinstance(catalogs_data, list)` check, so a FALSY
non-list `catalogs:` value (`{}`, `''`, `0`, `false`) was silently
swallowed as "no catalogs" — while a TRUTHY non-list
(`catalogs: "not-a-list"`) already raised "must be a list".
`WorkflowCatalog._load_catalog_config` and
`StepCatalog._load_catalog_config` (workflows/catalog.py) already
guard against both cases correctly, with the same explanatory
comments reused here. This preset sibling was missed.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt
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.
Summary
PresetCatalog._load_catalog_config(src/specify_cli/presets/__init__.py) has two instances of the same "emptiness check runs before the shape check" bug, both of which mask a corruptedpreset-catalogs.ymlas an empty/no-op config instead of raising a clear error:data = yaml.safe_load(config_path.read_text(...)) or {}coerces a FALSY non-mapping document ([],false,0,'') to{}before theisinstance(data, dict)guard runs — silently swallowed as "no config", while a TRUTHY non-mapping (a bare string) correctly raises"expected a mapping at root".catalogs_data = data.get("catalogs", [])followed byif not catalogs_data: return Nonechecks emptiness before checkingisinstance(catalogs_data, list). A FALSY non-listcatalogs:value ({},'',0,false) is silently treated as "no catalogs", while a TRUTHY non-list (catalogs: "not-a-list") correctly raises"must be a list".WorkflowCatalog._load_catalog_configandStepCatalog._load_catalog_config(src/specify_cli/workflows/catalog.py) already guard against exactly both cases, with explanatory comments (# Do NOT coerce with or {} here.../# Same asymmetry ... one nesting level down). This preset sibling wasn't updated to match. Fix reuses the same pattern and comments.Test plan
test_load_catalog_config_rejects_falsy_non_mapping_root(parametrized over[],false,0,'') andtest_load_catalog_config_rejects_falsy_non_list_catalogs(parametrized overcatalogs: {},'',0,false) toTestPresetCatalogMultiCatalog.TestPresetCatalogMultiCatalogin full — 33 passed, no regressions.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt