#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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070194944d8df4-68306f15-0d72-4ddb-928e-0912ba564e78-000000%40eu-central-1.amazonses.com.

Reply via email to