Edgewall Software

Opened 11 years ago

Closed 11 years ago

#11248 closed defect (fixed)

reST rendering can fail for TracStandalone

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 0.12.6
Component: wiki system Version: 0.12-stable
Severity: normal Keywords: rest docutils restructuredtext
Cc: Branch:
Release Notes:

reST rendering could fail when running TracStandalone due to Docutils importing the Trac standalone module rather than the Docutils module of the same name.

API Changes:
Internal Changes:


Rendering WikiRestructuredText can fail with the following error in the log (comment:8:ticket:12245):

2013-07-17 17:30:05,613 Trac[api] WARNING: HTML preview using ReStructuredTextRenderer failed:
Traceback (most recent call last):
  File "/home/user/Workspace/t11245-2.7/teo-rjollos2.git/trac/mimeview/api.py", line 773, in render
    rendered_content, filename, url)
  File "/home/user/Workspace/t11245-2.7/teo-rjollos2.git/trac/mimeview/rst.py", line 278, in render
    'warning_stream': False})
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 448, in publish_parts
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 657, in publish_programmatically
    pub.set_components(reader_name, parser_name, writer_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 93, in set_components
    self.set_reader(reader_name, self.parser, parser_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/core.py", line 82, in set_reader
    reader_class = readers.get_reader_class(reader_name)
  File "/home/user/Workspace/t11245-2.7/local/lib/python2.7/site-packages/docutils-0.10-py2.7.egg/docutils/readers/__init__.py", line 113, in get_reader_class
    return module.Reader
AttributeError: 'module' object has no attribute 'Reader'

The problem is with line 110 in docutils/readers/__init__.py (DocUtils version 0.10):

module = __import__(reader_name, globals(), locals(), level=0)

Since by default the module name is specified as reader_name = 'standalone', this can result in the import of <module 'standalone' from './trac/web/standalone.pyc'>.

The issue can be resolved by explicitly specifying the default reader:

  • trac/mimeview/rst.py

    diff --git a/trac/mimeview/rst.py b/trac/mimeview/rst.py
    index bce5cac..f7ce83b 100644
    a b try:  
    2929    from docutils import nodes
    3030    from docutils.core import publish_parts
    3131    from docutils.parsers import rst
     32    from docutils.readers import standalone
    3233    from docutils import __version__
    3334    has_docutils = True
    3435except ImportError:
    class ReStructuredTextRenderer(Component):  
    270271        inliner.trac = (self.env, context)
    271272        parser = rst.Parser(inliner=inliner)
    272273        content = content_to_unicode(self.env, content, mimetype)
     274        # Explicitly specifying the default Reader is a workaround for #11248
    273275        parts = publish_parts(content, writer=writer, parser=parser,
     276                              reader=standalone.Reader(parser),
    274277                              settings_overrides={'halt_level': 6,
    275278                                                  'warning_stream': False,
    276279                                                  'file_insertion_enabled': 0,

The lastest DocUtils version is 0.10, released in December 2012. The issue has been fixed in [7646], [7648] but the fix has not yet been incorporated into a formal release, and we'd need to support earlier versions of DocUtils anyway, so I propose to apply the workaround in 1.0-stable.

Attachments (0)

Change History (3)

comment:1 by Ryan J Ollos, 11 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:2 by Jun Omae, 11 years ago

Trac 0.12-stable with docutils 0.10 has the same issue except Python 2.4. I think we should apply in 0.12-stable.

After the patch, it works. I verified with

docutils Python
0.12-stable 0.6 and 0.10 2.4 and 2.6
1.0-stable 0.6 and 0.10 2.6

comment:3 by Ryan J Ollos, 11 years ago

Keywords: docutils restructuredtext added
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed
Version: 1.0dev0.12-stable

Thanks for the feedback Jun.

Applied in [11851], merged to 1.0-stable in [11852] and merged to trunk in [11853].

Fixed a benign unrelated issue on 1.0-stable in [11854] and merged to trunk in [11855].

Coincidentally, Docutils 0.11 was released today.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.