Django

Code

Ticket #6681 (reopened)

Opened 1 year ago

Last modified 7 months ago

Problem with restructuredtext in markup module

Reported by: mtredinnick Assigned to: nobody
Milestone: Component: Contrib apps
Version: SVN Keywords: markup bug
Cc: forsberg Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Trying to access http://www.djangoproject.com/documentation/0.96/tutorial01/ just now gave a traceback. Normal documentation (the equivalent current stuff) works fine.

Traceback (most recent call last):
File "/home/djangoproject.com/django/core/handlers/base.py" in _real_get_response
  81. response = callback(request, *callback_args, **callback_kwargs)
File "/home/djangoproject.com/django_website/apps/docs/views.py" in doc_detail
  40. parts = builder.build_document(client.cat(docpath))
File "/home/djangoproject.com/django_website/apps/docs/builder.py" in build_document
  16. return publish_parts(text, writer=DjangoHTMLWriter(), settings_overrides={'initial_header_level': 2})
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/core.py" in publish_parts
  431. enable_exit_status=enable_exit_status)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/core.py" in publish_programmatically
  612. output = pub.publish(enable_exit_status=enable_exit_status)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/core.py" in publish
  202. self.settings)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/readers/__init__.py" in read
  69. self.parse()
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/readers/__init__.py" in parse
  75. self.parser.parse(self.input, document)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/__init__.py" in parse
  157. self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  170. input_source=document['source'])
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in text
  2883. self.section(title.lstrip(), source, style, lineno + 1, messages)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in section
  308. self.new_subsection(title, lineno, messages)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in new_subsection
  376. node=section_node, match_titles=1)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in nested_parse
  266. node=node, match_titles=match_titles)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  195. results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in underline
  2658. self.section(title, source, style, lineno - 1, messages)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in section
  308. self.new_subsection(title, lineno, messages)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in new_subsection
  376. node=section_node, match_titles=1)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in nested_parse
  266. node=node, match_titles=match_titles)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  195. results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in indent
  1081. elements = self.block_quote(indented, line_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in block_quote
  1096. self.nested_parse(blockquote_lines, line_offset, blockquote)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in nested_parse
  266. node=node, match_titles=match_titles)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  195. results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in bullet
  1187. blank_finish=blank_finish)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in nested_list_parse
  300. node=node, match_titles=match_titles)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  195. results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in bullet
  2417. listitem, blank_finish = self.list_item(match.end())
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in list_item
  1203. node=listitem)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in nested_parse
  266. node=node, match_titles=match_titles)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in run
  195. results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in run
  232. context, state, transitions)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/statemachine.py" in check_line
  420. return method(match, context, next_state)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in text
  2672. paragraph, literalnext = self.paragraph(lines, startline)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in paragraph
  399. textnodes, messages = self.inline_text(text, lineno)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in inline_text
  408. return self.inliner.parse(text, lineno, self.memo, self.parent)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in parse
  492. lineno)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in interpreted_or_phrase_ref
  746. lineno)
File "/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg/docutils/parsers/rst/states.py" in interpreted
  802. nodes, messages2 = role_fn(role, rawsource, text, lineno, self)
File "/home/djangoproject.com/django/contrib/admin/utils.py" in default_reference_role
  93. context = inliner.document.settings.default_reference_context

  AttributeError at /documentation/0.96/tutorial01/
  Values instance has no attribute 'default_reference_context'

Attachments

Change History

02/27/08 22:25:59 changed by jacob

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to wontfix.
  • needs_tests changed.
  • needs_docs changed.

Meh, this happens every time I restart Apache. It's something to do with the nasty monkeypatching I'm doing to docutils, but since it goes away quickly I can never reproduce it long enough to figure out what's wrong.

05/18/08 05:30:11 changed by zeth <theology@gmail.com>

  • keywords set to markup.
  • resolution deleted.
  • status changed from closed to reopened.
  • component changed from Django Web site to Contrib apps.
  • summary changed from Serving old docs on djangoproject.com is broken. to Problem with restructuredtext in markup module.

I'm having the same bug as Jacob encountered but I have done no "nasty monkeypatching". I am using plain SVN Django and the default Debian docutils.

Let me be more specific:

I am using the FreeComment from the contrib Comments module, and then filtering the comments through the markup module's restructuredtext filter. Like this:

{{ comment.comment|escape|restructuredtext }}

Certain user input will kill the restructuredtext filter. For example, this piece of markdown:

(http://google.com)[blah]

AttributeError? at [absolute URL]

Will give:

Values instance has no attribute 'default_reference_context'

In template [template], error at line 66 Caught an exception while rendering: Values instance has no attribute 'default_reference_context'

Line 66 is our friend: {{ comment.comment|escape|restructuredtext }}

05/18/08 05:32:52 changed by zeth <theology@gmail.com>

My example user input got filtered by Trac, here it is escaped:

`(http://google.com)[blah]`

05/18/08 05:39:09 changed by zeth <theology@gmail.com>

The full traceback:

Traceback: File "/my-django-location/django/template/debug.py" in render_node

  1. result = node.render(context)

File "/my-django-location/django/template/debug.py" in render

  1. output = force_unicode(self.filter_expression.resolve(context))

File "/my-django-location/django/template/init.py" in resolve

  1. new_obj = func(obj, *arg_vals)

File "/my-django-location/django/contrib/markup/templatetags/markup.py" in restructuredtext

  1. parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)

File "/usr/lib/python2.4/site-packages/docutils/core.py" in publish_parts

  1. enable_exit_status=enable_exit_status)

File "/usr/lib/python2.4/site-packages/docutils/core.py" in publish_programmatically

  1. output = pub.publish(enable_exit_status=enable_exit_status)

File "/usr/lib/python2.4/site-packages/docutils/core.py" in publish

  1. self.settings)

File "/usr/lib/python2.4/site-packages/docutils/readers/init.py" in read

  1. self.parse()

File "/usr/lib/python2.4/site-packages/docutils/readers/init.py" in parse

  1. self.parser.parse(self.input, document)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/init.py" in parse

  1. self.statemachine.run(inputlines, document, inliner=self.inliner)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in run

  1. input_source=documentsource?)

File "/usr/lib/python2.4/site-packages/docutils/statemachine.py" in run

  1. result = state.eof(context)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in eof

  1. self.blank(None, context, None)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in blank

  1. paragraph, literalnext = self.paragraph(

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in paragraph

  1. textnodes, messages = self.inline_text(text, lineno)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in inline_text

  1. return self.inliner.parse(text, lineno, self.memo, self.parent)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in parse

  1. lineno)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in interpreted_or_phrase_ref

  1. lineno)

File "/usr/lib/python2.4/site-packages/docutils/parsers/rst/states.py" in interpreted

  1. nodes, messages2 = role_fn(role, rawsource, text, lineno, self)

File "/my-django-location/django/contrib/admin/utils.py" in default_reference_role

  1. context = inliner.document.settings.default_reference_context

Exception Type: AttributeError? at /absolute/url/of/content/object/ Exception Value: Values instance has no attribute 'default_reference_context'

07/29/08 15:01:33 changed by edgarsj

  • keywords changed from markup to markup bug.
  • stage changed from Unreviewed to Accepted.

12/03/08 13:54:08 changed by forsberg

I'm experiencing the same problem. I think I have an idea on what's causing it. It seems like if the bug is triggered by a combination of the following:

1. The apache process is just started.

2. The first (I think it's the first, not sure) request that hits the process is for a page that requires processing by contrib.markup.templatetags.markup.restructuredtext.

3. There's some interpreted text using the default role in the reST. Example:

  `interpreted text using the default role`

This text will, in the standard case, be parsed by the reST role named by the variable DEFAULT_INTERPRETED_ROLE in docutils/parsers/rst/roles.py, but django/contrib/admindocs/utils.py (in rev 7967, it's line 100) sets it to 'cmsreference'. I think that's what's causing the problem. Verifying that right now by running my server which got lot's of these errors yesterday with a modified django where the offending line has been disabled.

I have not analyzed why this seems to happen only now and then. I also don't know why admindocs/utils.py is setting DEFAULT_INTERPRETED_ROLE, but it does look like a bad thing to do.

12/03/08 13:55:33 changed by forsberg

  • cc set to forsberg.

12/04/08 13:03:04 changed by forsberg

Can confirm after about 24h of no-trouble-uptime that my workaround is indeed a valid workaround.


Add/Change #6681 (Problem with restructuredtext in markup module)




Change Properties
Action