🐛 Fix needs.json read/write when no needs are present#1661
Merged
chrisjsewell merged 4 commits intouseblocks:masterfrom Feb 23, 2026
Merged
🐛 Fix needs.json read/write when no needs are present#1661chrisjsewell merged 4 commits intouseblocks:masterfrom
needs.json read/write when no needs are present#1661chrisjsewell merged 4 commits intouseblocks:masterfrom
Conversation
Fix producer-side by always adding the structures. Fix consumer-side by accepting missing structure. Fixes useblocks#1569
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1569 where having zero needs in a documentation would result in a broken needs.json file that couldn't be consumed by other projects. The fix implements both producer-side and consumer-side changes to handle empty needs gracefully.
Changes:
- Producer-side: Always create version structure in needs.json even when there are no needs
- Consumer-side: Gracefully handle external needs.json files with empty versions dict
- Add comprehensive test coverage for both scenarios
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sphinx_needs/needsfile.py | Added call to update_or_add_version in _finalise() to ensure version structure is always created |
| sphinx_needs/external_needs.py | Added check for empty versions dict to avoid KeyError when loading external needs |
| tests/test_needs_builder.py | Added test test_doc_needs_builder_empty to verify empty docs produce valid needs.json |
| tests/test_external.py | Added test test_external_empty_versions to verify empty external needs.json doesn't crash |
| tests/doc_test/doc_needs_builder_empty/index.rst | Test fixture: empty documentation without needs |
| tests/doc_test/doc_needs_builder_empty/conf.py | Test fixture: minimal configuration for empty doc test |
| tests/snapshots/test_needimport.ambr | Updated snapshot to reflect new version structure in empty needs case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
needs.json read/write when no needs are present
Member
|
please update the branch so I can merge |
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.
Fix producer-side by always adding the structures.
Fix consumer-side by accepting missing structure.
Fixes #1569