Fix AssertionError when confval default contains cross-reference - #14643
Draft
aryansk wants to merge 1 commit into
Draft
Fix AssertionError when confval default contains cross-reference#14643aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
The confval directive's :default: option is formatted via parse_inline into a field_body. Previously it placed inline nodes directly into field_body, so a reference like :confval:`conf1` inside :default: had a parent of field_body (not a TextElement). The HTML writer then hit the assert for non-TextElement parents: assert len(node) == 1 and isinstance(node[0], nodes.image) Wrapping the parsed inline nodes in a paragraph (a TextElement) fixes the structure, so references are inside a paragraph inside field_body, matching normal field handling. Fixes sphinx-doc#14117 Co-authored-by: Muse Spark <muse-spark@users.noreply.github.com> Co-authored-by: Aryan Singh K <70511529+aryansk@users.noreply.github.com> AI disclosure: Muse Spark assisted in analysis and fix drafting; changes reviewed and tested manually (reproduction with :confval: in :default: now builds, HTML contains link, 20 test_domain_std tests pass).
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.
Problem
Given a file like:
The build crashes with:
Same happens with
:envvar:inside:default:(e.g... confval:: conf1 :default: :envvar:ENV1``). The problem is any cross-reference in:default:or `:type:` when the target exists.Fixes #14117
Change
In
sphinx/domains/std/__init__.py,ConfigurationValue.format_typeandformat_defaultpreviously did:parse_inlinereturns inline nodes (Text +pending_xref/reference) directly. Placing them directly intofield_bodymeans areference's parent isfield_body(not aTextElement). The HTML5 writer then asserts:— expecting only image references outside TextElement. Wrapping the parsed nodes in a
paragraph(which is aTextElement) fixes the hierarchy:Single-file, 2-line fix covering both
:type:and:default:.Why this approach
field_bodyis defined to hold block elements; normalfield_listentries wrap inline content in aparagraph. The confval:type:/:default:fields were the outlier. Adding the paragraph matches the rest of the codebase and fixes the writer assert without touching the writer itself (which correctly distinguishes image vs text references).Testing
Documentation and release impact
Review notes
AI disclosure
Muse Spark assisted in analysis and drafting; all changes reviewed and tested manually. Co-authored-by trailers included for Pair Extraordinaire.
Co-authored-by: Muse Spark muse-spark@users.noreply.github.com
Co-authored-by: Aryan Singh K 70511529+aryansk@users.noreply.github.com