#36124: Importing from django.contrib.admindocs.views modifies docutils rst parser
-------------------------------------+-------------------------------------
Reporter: Michal Čihař | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admindocs | Version: dev
Severity: Normal | Resolution: needsinfo
Keywords: docutils | Triage Stage:
simplify_regex roles | Unreviewed
register_canonical_role |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Michal Čihař):
Using the private API is not required to trigger my original issue. It is
just the way I hit it. The issue can be reproduced by importing
`django.contrib.admindocs.views` or `django.contrib.admindocs.utils`:
{{{
import django.contrib.admindocs.views
import docutils.utils
from docutils.core import Publisher
publisher = Publisher()
publisher.set_components("standalone", "restructuredtext", "null")
settings = publisher.get_settings()
document = docutils.utils.new_document('<rst-doc>', settings=settings)
publisher.reader.parser.parse(":tag:`foo`", document)
}}}
It crashes with
{{{
Traceback (most recent call last):
File "/home/nijel/weblate/weblate/test.py", line 14, in <module>
parser.parse(":tag:`foo`", document)
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/__init__.py", line 184, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 169, in run
results = StateMachineWS.run(self, input_lines, input_offset,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/statemachine.py", line 239, in run
result = state.eof(context)
^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 2727, in eof
self.blank(None, context, None)
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 2718, in blank
paragraph, literalnext = self.paragraph(
^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 416, in paragraph
textnodes, messages = self.inline_text(text, lineno)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 425, in inline_text
nodes, messages = self.inliner.parse(text, lineno,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 649, in parse
before, inlines, remaining, sysmessages = method(self, match,
^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 792, in
interpreted_or_phrase_ref
nodelist, messages = self.interpreted(rawsource, escaped, role,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/docutils/parsers/rst/states.py", line 889, in interpreted
nodes, messages2 = role_fn(role, rawsource, text, lineno, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nijel/weblate/weblate/.venv/lib/python3.11/site-
packages/django/contrib/admindocs/utils.py", line 116, in _role
inliner.document.settings.link_base,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Values' object has no attribute 'link_base'
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36124#comment:4>