Skip to content

fix(integrations): report a falsy non-mapping integration descriptor as a shape error - #4187

Open
Noor-ul-ain001 wants to merge 4 commits into
github:mainfrom
Noor-ul-ain001:fix/integration-descriptor-falsy-shape
Open

fix(integrations): report a falsy non-mapping integration descriptor as a shape error#4187
Noor-ul-ain001 wants to merge 4 commits into
github:mainfrom
Noor-ul-ain001:fix/integration-descriptor-falsy-shape

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

IntegrationDescriptor._load (in src/specify_cli/integrations/catalog.py) does yaml.safe_load(fh) or {}. _validate opens with an isinstance(self.data, dict) check, so a truthy non-mapping (- a, hello) is reported correctly as a shape error — but or {} replaces falsy non-mappings with an empty mapping before that check ever runs, so those descriptors were reported as Missing required field: schema_version instead of the actual problem:

integration.yml content Before After
false Missing required field: schema_version Descriptor root must be a YAML mapping, got bool
0 Missing required field: schema_version Descriptor root must be a YAML mapping, got int
'' Missing required field: schema_version Descriptor root must be a YAML mapping, got str
[] Missing required field: schema_version Descriptor root must be a YAML mapping, got list
null / ~ / NULL Missing required field: schema_version Descriptor root must be a YAML mapping, got NoneType
(empty file) Missing required field: schema_version unchanged — still Missing required field: schema_version

safe_load returns None for both an explicit null scalar and a genuinely empty document, so a plain data is None normalization can't tell them apart either. This uses yaml.compose, which yields no node only for a genuinely empty document, to keep the empty-file case reporting its missing fields while every other non-mapping shape (including explicit null) now surfaces the real error.

This is the same bug class a maintainer fixed the same day in the sibling overlay-manifest loader (ProjectOverlaySource.collect, commit 39c36c4 / #3884) — that PR's description even calls out that the pattern should be checked elsewhere. This is the unfixed twin in the integration catalog's descriptor loader.

Test plan

  • Added TestIntegrationDescriptor::test_falsy_non_mapping_descriptor_reports_shape_error (parametrized over [], false, 0, '', null, ~, NULL, - a, hello) and test_empty_document_still_reports_missing_fields
  • Verified the new tests fail without the fix (7 of 10 cases) and pass with it
  • pytest tests/integrations/test_integration_catalog.py — 133 passed
  • ruff check on both changed files — clean

🤖 Generated with Claude Code

…as a shape error

`IntegrationDescriptor._load` did `yaml.safe_load(fh) or {}`. `_validate`
opens with an `isinstance(self.data, dict)` check, so a truthy non-mapping
(`- a`, `hello`) is reported correctly -- but `or {}` replaced the falsy
non-mappings with an empty mapping first, so those descriptors were
reported as "Missing required field: schema_version" instead of the wrong
shape:

  'false' -> Descriptor root must be a YAML mapping, got bool
  '0'     -> Descriptor root must be a YAML mapping, got int
  "''"    -> Descriptor root must be a YAML mapping, got str
  '[]'    -> Descriptor root must be a YAML mapping, got list

`safe_load` also returns None for an explicit null scalar (`null`, `~`,
`NULL`) as well as for an empty document, so those three hit the same
masking. Use `yaml.compose`, which yields no node only for a genuinely
empty document, to tell the two apart -- only an empty document still
normalizes to `{}` and reports its missing fields.

Same bug class just fixed in the sibling overlay-manifest loader
(upstream commit 39c36c4, PR github#3884); this is the unfixed twin in the
integration catalog's descriptor loader.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes integration descriptor validation so falsy non-mapping YAML values report shape errors.

Changes:

  • Distinguishes empty YAML from explicit null values.
  • Adds regression coverage for non-mapping and empty descriptors.
Show a summary per file
File Description
src/specify_cli/integrations/catalog.py Refines YAML loading and empty-document handling.
tests/integrations/test_integration_catalog.py Tests descriptor shape errors and empty files.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/specify_cli/integrations/catalog.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/specify_cli/integrations/catalog.py Outdated

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread tests/integrations/test_integration_catalog.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

3 participants