Skip to content

🐛 Fix needs.json read/write when no needs are present#1661

Merged
chrisjsewell merged 4 commits intouseblocks:masterfrom
qznc:fix-1569
Feb 23, 2026
Merged

🐛 Fix needs.json read/write when no needs are present#1661
chrisjsewell merged 4 commits intouseblocks:masterfrom
qznc:fix-1569

Conversation

@qznc
Copy link
Contributor

@qznc qznc commented Feb 21, 2026

Fix producer-side by always adding the structures.

Fix consumer-side by accepting missing structure.

Fixes #1569

qznc and others added 3 commits February 21, 2026 16:21
Fix producer-side by always adding the structures.

Fix consumer-side by accepting missing structure.

Fixes useblocks#1569
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@chrisjsewell chrisjsewell changed the title Zero needs does not break needs.json anymore 🐛 Fix needs.json read/write when no needs are present Feb 23, 2026
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

cheers!

@chrisjsewell
Copy link
Member

chrisjsewell commented Feb 23, 2026

please update the branch so I can merge

@chrisjsewell chrisjsewell merged commit 0aea09e into useblocks:master Feb 23, 2026
22 checks passed
@qznc qznc deleted the fix-1569 branch February 23, 2026 19:03
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.

No needs results in broken needs.json

3 participants