Skip to content

fix: preserve 'state' field when adding external needs - #2404

Closed
Vijaysir0hi wants to merge 1 commit into
useblocks:masterfrom
Vijaysir0hi:fix/preserve-external-need-state
Closed

Vijaysir0hi wants to merge 1 commit into
useblocks:masterfrom
Vijaysir0hi:fix/preserve-external-need-state

Conversation

@Vijaysir0hi

Copy link
Copy Markdown

Fixes #2403

Summary

When an external needs source declares a custom field named state, add_external_need previously stripped state from kwargs because it was listed alongside non-field metadata (docname, lineno, is_external).

In addition, because add_need declares state: RSTState | None = None in its signature, passing state as a keyword argument assigns it to that parameter rather than forwarding it in kwargs to generate_need.

Changes

  1. Removed state from the fixed_key tuple in add_external_need.
  2. In add_need, if state is not an RSTState (i.e. a custom field value passed for an external need), restore it to kwargs["state"], so generate_need receives and stores the field.
  3. Added a regression test in tests/test_external.py verifying that an external need with state: "draft" preserves the field value in get_needs_view().

External needs declared with a custom field named 'state' were previously losing
the value because add_external_need dropped 'state' alongside internal parameters.
In add_need, a non-RSTState value is restored to kwargs so it is passed to
generate_need and persisted on the external need record.

Signed-off-by: Vijay Sirohi <191354616+Vijaysir0hi@users.noreply.github.com>
@github-actions github-actions Bot added the pkg: sphinx-needs The sphinx-needs distribution (packages/sphinx-needs): its code, tests and docs label Oct 30, 2026
@chrisjsewell

Copy link
Copy Markdown
Member

Thank you for picking this up, and for the test.

#2403 was fixed as part of #2406 (merged as 8bd37988a). That PR moved every way sphinx-needs creates a need onto one internal path that takes a need's fields as a mapping, never as keyword arguments. The external reader now uses that path, and add_external_need keeps a state that the project declares as a field. Because the fix came with that larger change, this PR is no longer needed, so I'm closing it.

Thanks again for the report-shaped test. It matched what we measured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: sphinx-needs The sphinx-needs distribution (packages/sphinx-needs): its code, tests and docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 An external need silently loses a field named state: add_external_need drops it from the record

2 participants