Skip to content

fix(workflows): reject falsy non-mapping catalog config in add/remove - #4319

Open
Noor-ul-ain001 wants to merge 1 commit into
github:mainfrom
Noor-ul-ain001:fix/catalog-remove-add-falsy-config
Open

fix(workflows): reject falsy non-mapping catalog config in add/remove#4319
Noor-ul-ain001 wants to merge 1 commit into
github:mainfrom
Noor-ul-ain001:fix/catalog-remove-add-falsy-config

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

  • WorkflowCatalog.remove_catalog, StepCatalog.add_catalog, and StepCatalog.remove_catalog (all in src/specify_cli/workflows/catalog.py) read their config file with yaml.safe_load(config_path.read_text(...)) or {}.
  • That or {} coerces a falsy non-mapping top-level document ([], false, 0, '') to {} before the isinstance(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 for remove_catalog it surfaces as a misleading "Catalog index N out of range" error instead.
  • WorkflowCatalog._load_catalog_config (the shared loader behind get_active_catalogs) and WorkflowCatalog.add_catalog already 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.
  • Same bug shape as fix(presets): reject malformed catalog roots during mutation #4094 (preset catalog add/remove) and fix(integrations): report a falsy non-mapping integration descriptor as a shape error #4187 (integration descriptor loading) — falsy-or-coerce masking a shape error.

Test plan

  • Added test_remove_catalog_rejects_falsy_non_mapping_config to TestWorkflowCatalog and test_add_catalog_rejects_falsy_non_mapping_config / test_remove_catalog_rejects_falsy_non_mapping_config to TestStepCatalog, each parametrized over [], false, 0, ''.
  • Verified all 12 new parametrized cases fail without the fix (stashed only the source change) and pass with it.
  • Ran TestWorkflowCatalog + TestStepCatalog in full — 100 passed, no regressions.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt

@Noor-ul-ain001
Noor-ul-ain001 requested a review from mnriem as a code owner August 25, 2026 14:48
`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
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.

1 participant