fix(integrations): validate cached catalog shape before returning it#3627
Open
jawwad-ali wants to merge 1 commit into
Open
fix(integrations): validate cached catalog shape before returning it#3627jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
The catalog cache-read branch returned json.loads(cache_file) directly, skipping
the shape validation the fresh-fetch branch enforces (dict root + 'integrations'
mapping). A poisoned or older-format cache (e.g. {"integrations": []}) was
therefore returned as-is and later crashed with 'AttributeError: list object has
no attribute items' when the caller iterated integrations. Validate the cached
object the same way; the raised ValueError is already caught by the surrounding
handler, which drops the corrupt cache and refetches from source.
Test: a fresh-but-mis-shaped cache is dropped and the valid source refetched
(fails before: AttributeError).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Validates cached integration catalogs before reuse to prevent malformed data from causing downstream crashes.
Changes:
- Adds cache payload shape validation and recovery.
- Adds a regression test for malformed cached integrations.
- One issue remains: cached payloads can omit
schema_version.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/integrations/catalog.py |
Validates cached catalog structure before returning it. |
tests/integrations/test_integration_catalog.py |
Tests malformed-cache deletion and refetching. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
Comment on lines
+162
to
+164
| if not isinstance(cached, dict) or not isinstance( | ||
| cached.get("integrations"), dict | ||
| ): |
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.
What
IntegrationCatalog's fetch validates a fresh payload's shape (root must be a JSON object,integrationsmust be a mapping) before use — but the cache-read branch returned the cached object directly:So a poisoned or older-format cache (e.g.
{"integrations": []}) is returned as-is and later crashes withAttributeError: 'list' object has no attribute 'items'when the caller iteratesintegrations.Fix
Validate the cached object with the same key checks as the fresh-fetch path before returning it. The raised
ValueErroris already caught by the existing surroundingexcept (… ValueError …), which deletes the corrupt cache files and refetches from source — the same recovery a poisoned network payload already gets.Test
test_poisoned_cache_shape_is_dropped_and_refetched: a fresh-but-mis-shaped cache (integrationsas a list) is dropped and the valid source refetched — fails before (AttributeError), passes after.🤖 Written with the assistance of Claude Code (AI). Bug self-found; fix/tests verified locally (fail-before / pass-after), ruff clean.