You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible data loss with sphinx.util.parsing.nested_parse_to_nodes() #13845
The utility function nested_parse_to_nodes() provides the boolean parameter keep_title_context".
If this parameter is True, parsing is done by docutils.parsers.rst.state.RSTState.nested_parse() with the document-wide "title style hierarchy".
Recent testing revealed that this method can loose complete sections without warning when the rST input contains sections with a title style that matches a lower section level than the current section level.
The most sensible simple solution for Docutils is to always use a new "title style context" with nested parsing, which overrides the "keep_title_context" argument.
It seems Sphinx itself never uses nested_parse_to_nodes() with keep_title_context=True.
If there is a convincing use case for keep_title_context=True, we might try to find a save implementation. In this case, Sphinx should define and test the desired behaviour when a nested section title uses the style of a lower section level than the section containing the directive using nested_parse_to_nodes().
Otherwise I suggest to emit a warning like "nested parsing always uses a separate title style context in Docutils >= 0.23."
FAILED tests/test_directives/test_directive_only.py::test_sectioning - AssertionError: Section out of place: '1.6.2. Subsection'
assert '1.6.1.1.' == '1.6.2.'
This is the "only" directive failing if it tries to re-attach/move sections with a higher level up in the document tree (by some "dark magic", so failure was kind of expected -- this is why I did not yet make a bugfix release with these changes).
Activity
AA-Turner commentedon Aug 19, 2025
Thanks @gmilde! I'm on holiday for the next week but will try and investigate.
A
jfbu commentedon Aug 21, 2025
Our own testing with Docutils HEAD now fails since r10204. The r10205, r10206 and subsequent commits to Docutils did not modify that.
The failing test (and all others)
tests/test_directives/test_directive_only.py::test_sectioningpasses atr10203of Docutils.Note that the LaTeX/CI failure is a duplicate and a collateral to the fact that LaTeX/CI now uses Docutils HEAD.
@gmilde It seems the revision numbers were shifted by one in your OP, so I edited them. Please revert if I erred.
gmilde commentedon Aug 21, 2025
This is the "only" directive failing if it tries to re-attach/move sections with a higher level up in the document tree (by some "dark magic", so failure was kind of expected -- this is why I did not yet make a bugfix release with these changes).
See #13861 for possible fixes.
Add warning about possible data loss to dangerous function argument.
jfbu commentedon Sep 6, 2025
Update: as @gmilde mentions at #13861 (comment) our ``only directive'' test passes again since [r10226] rST parser: restore backwards compatibility ....
(to confirm I relaunched the failed jobs at current tip of master eaebbec)