Open openlegis-br opened 3 weeks ago
OpenLegis wrote at 2024-8-19 08:08 -0700:
BUG/PROBLEM REPORT / FEATURE REQUEST
2024-08-19 12:03:19,269 ERROR [waitress:435][waitress-0] Exception while serving /sagl/cadastros/materia/sapl_documentos/materiaodt/externalEdit/72109_texto_integral.odt.zem Traceback (most recent call last): ... File "/var/openlegis/SAGL5/eggs/Products.ExternalEditor-4.0-py3.10.egg/Products/ExternalEditor/ExternalEditor.py", line 224, in index_html for data in body: File "/var/openlegis/SAGL5/eggs/Products.ExternalEditor-4.0-py3.10.egg/Products/ExternalEditor/ExternalEditor.py", line 52, in next self.data = next(self.data) TypeError: 'Acquisition.ImplicitAcquisitionWrapper' object is not an iterator
This looks more like a data error in your ZODB than a
bug in ExternalEditor
: "AquicisitonWrapper"'s delegate most
operations (such as __next__
) to the wrapped object; thus the
error your observe likely results from the wrapped object not supporting
__next__
.
I suggest you analyse the context of the TypeError
with a debugger
(my favorite way is to use Products.PDBDebugMode
which
enters the Python debugger in case of an unhandled exception
(provided Zope
runs in debug/development mode)).
Unwrap self.deta
(self.data.aq_base
) and look at the result type.
The solution that worked for me was to change line 52 of the ExternalEditor.py file, from: self.data = next(self.data) to: self.data = self.data.next
OpenLegis wrote at 2024-9-14 08:13 -0700:
The solution that worked for me was to change line 52 of the ExternalEditor.py file, from: self.data = next(self.data) to: self.data = self.data.next
I am still convinced that the problem is elsewhere.
Have you found out what type self.data
has?
Apparently, there is a Python 2/3 incompatibility there:
Python 2 uses the next
, Python 3 __next__
for the iterator protocol.
Apparently, the above type forgets to define __next__
.
I was unable to debug with Products.PDBDebugMode.
But I ran several tests and found the following:
1) Not all ODT files produce the error when trying to edit, it depends on their content (it seems to be something related to binary content, such as an image or link, for example), and there is no way to identify what exactly inside the file generates the error.
2) Even files with an error when trying to edit can be downloaded normally, so they are not corrupted in ZoDB
3) Based on this, it can be concluded that the problem is not directly related to ZPublisher, Acquisition, ZoDB or waitress.
I tested the solution in Python 3.10 and 3.12. So far, the solution found has worked well.
Thank you for your time.
@.*** wrote at 2024-9-14 17:49 +0200:
OpenLegis wrote at 2024-9-14 08:13 -0700:
The solution that worked for me was to change line 52 of the ExternalEditor.py file, from: self.data = next(self.data) to: self.data = self.data.next
I am still convinced that the problem is elsewhere.
Likely, I have been wrong:
The code above belongs to the class PDataStreamIterator
.
The name suggests that it should implement an iterator
for OFS.Image.Pdata
instances, but it does not fit the Pdata
definition.
Your fix is the right one.
Your observation that the error happens only for some files
likely comes from the fact, that Pdata
elements are only used
for sufficiently large files; smaller files have the content
in a bytes
(rather than Pdata
) object.
Would you like to become a zopefoundation
(Zope
) contributor?
You would then be able to fix this problem yourself.
I would be happy to make this small contribution to the community.
OpenLegis wrote at 2024-9-14 14:40 -0700:
I would be happy to make this small contribution to the community.
You would need to sign the "Zope
contributor agreement"
and then create a github
pull request (short "PR").
The PR would contain your correction and an entry in CHANGES.rst
to describe your modification.
After a review, you will be able to merge your PR.
I could help you with the PR, if necessary.
BUG/PROBLEM REPORT / FEATURE REQUEST
What version of Python and Zope/Addons I am using:
Python 3.10 Zope 5.10