Closed n1k9 closed 1 year ago
Thank you for writing this issue. It seems to be an edge case as it happens in a very commonly used function and this seems to be the first report of this issue.
Could you please use a debugger to find out why the body
variable is a str
object instead of bytes
?
Could you please use a debugger to find out why the
body
variable is astr
object instead ofbytes
?
Apparently, this happens for DTMLMethod
objects (maybe only for DTMLMethod
's which have been migrated from Python 2 to Python 3).
For a DTMLMethod
, https://github.com/zopefoundation/Products.ExternalEditor/blob/ecce6f48b69bf0bb91af26b30eed7912661f4b33/src/Products/ExternalEditor/ExternalEditor.py#L213 , i.e, document_src
, is responsible to determine the editable data. In my instance (migrated from Python 2 to Python 3), it returns str
(not bytes
) for the DTMLMethod
standard_error_message
.
@d-maurer So you think this is a bug in DTMLMethod
and should be fixed there?
From my quick reading over the source code the DTML objects expect the source code to be a native string. This did not change after the move to Python 3. document_src
returns that source code unchanged. Under Python 2 this would have been bytes
, but now it's str
. IMHO ExternalEditor needs to be fixed to account for that.
Michael Howitz wrote at 2022-10-12 23:26 -0700:
@.*** So you think this is a bug in DTMLMethod
and should be fixed there?
I am not sure but my feeling is: document_src
is likely
used for other purposes as well (e.g. editing the object, indexing
the object) where it is expected to be str
.
For those of us who meanwhile needs to get this to work, i just typecasted the body object in the ExternalEditor.py on line 238 as indicated by the error message. I just wrapped the "body" into a "bytes(body,'utf-8')", so the full line reads:
return b'\n'.join((metadata,bytes(body,'utf-8')))
This works, and i have had no detrimental effects whatsoever. I am using Zope 5.8.3, but it was originally tested and installed on Zope 5.3. the typecast seem to me as the safest way as a typecast of an object that already is a bytes object will do nothing, while strings gets the correct format.
I have created a PR at https://github.com/zopefoundation/Products.ExternalEditor/pull/22 for fixing the issue. Please try it out.
When try to use ExternalEditor the server return Internal Server Error (500) but in response there is base64 encode file
and in event.log there is this
Python 3.9.7 / Zope 5.5.1 / ExternalEditor 3.1.0