fix(workflows): reject falsy non-mapping catalog config in add/remove - #4319
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(workflows): reject falsy non-mapping catalog config in add/remove#4319Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
`WorkflowCatalog.remove_catalog`, `StepCatalog.add_catalog`, and
`StepCatalog.remove_catalog` all read their config file with
`yaml.safe_load(...) or {}`, which coerces a FALSY non-mapping
top-level document (`[]`, `false`, `0`, `''`) to `{}` before the
`isinstance(data, dict)` check ever runs — silently swallowing a
corrupted config instead of raising, while a truthy non-mapping
(`5`, a bare list with items) correctly raises.
`WorkflowCatalog._load_catalog_config` (used by `get_active_catalogs`)
and `WorkflowCatalog.add_catalog` already guard against this
correctly, with a comment explaining why `or {}` is wrong here; the
other three call sites in the same file reimplement the read inline
and missed the fix. Same shape as the falsy-or-coerce bug class fixed
in github#4094 (preset catalog add/remove) and github#4187 (integration
descriptor loading).
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
WorkflowCatalog.remove_catalog,StepCatalog.add_catalog, andStepCatalog.remove_catalog(all insrc/specify_cli/workflows/catalog.py) read their config file withyaml.safe_load(config_path.read_text(...)) or {}.or {}coerces a falsy non-mapping top-level document ([],false,0,'') to{}before theisinstance(data, dict)guard runs, so a corrupted config silently becomes "no catalogs" instead of raising"...corrupted (expected a mapping)". A truthy non-mapping (5, a bare list with items) already raised correctly — this was an inconsistency, and forremove_catalogit surfaces as a misleading"Catalog index N out of range"error instead.WorkflowCatalog._load_catalog_config(the shared loader behindget_active_catalogs) andWorkflowCatalog.add_catalogalready guard against exactly this, with an explanatory comment (# Do NOT coerce with or {} here: ...). The other three call sites in the same file reimplement the read inline and were missed.Test plan
test_remove_catalog_rejects_falsy_non_mapping_configtoTestWorkflowCatalogandtest_add_catalog_rejects_falsy_non_mapping_config/test_remove_catalog_rejects_falsy_non_mapping_configtoTestStepCatalog, each parametrized over[],false,0,''.TestWorkflowCatalog+TestStepCatalogin full — 100 passed, no regressions.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt