Comment 1 for bug 142590

Revision history for this message
Drew Ferguson (blacktav) wrote :

Calling manage_edit on a DTMLDocument sometimes barfs with

Traceback (innermost last):
  Module ZPublisher.Publish, line 98, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 39, in call_object
  Module OFS.DTMLMethod, line 126, in __call__
  Module DocumentTemplate.DT_String, line 474, in __call__
  Module DocumentTemplate.DT_Util, line 201, in eval
   - __traceback_info__: setBodyContents
  Module <string>, line 2, in f
  Module Shared.DC.Scripts.Bindings, line 252, in __call__
  Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 315, in _exec
  Module Script (Python), line 11, in setBodyContents
   - <PythonScript at /PF/setBodyContents used for /PF/news>
   - Line 11
  Module OFS.DTMLDocument, line 77, in manage_edit
  Module ZPublisher.TaintedString, line 89, in __getattr__
AttributeError: read

For instance, from a python script

  bodyStr = string.replace( bodyStr, '\015\012\015\012', '<br>\015\012<br>\015\012' )
  context['body_contents'].manage_edit( data=bodyStr, title='Body Contents' )

For plain text, the call is fine - if the text contains markup, it fails

Relevant line (77) in DTMLDocumemt.py is

  if type(data) is not type(''): data=data.read()

For data containing markup, type(data) is resolving as <type instance> which presumably has no attribute read.

Workaround is to coerce the variable to a string with

  context['body_contents'].manage_edit( data=str(bodyStr), title='Body Contents' )