zopefoundation / zope.publisher

Map requests from HTTP/WebDAV clients, web browsers, XML-RPC and FTP clients onto Python objects
Other
3 stars 13 forks source link

AttributeError: 'FileUpload' object has no attribute 'seekable' #44

Closed mgedmin closed 1 month ago

mgedmin commented 5 years ago

If you pass self.request['file_field'] to zipfile.ZipFile() on Python 3.7, you will get this error:

Traceback (most recent call last):
    ...
  File "/usr/lib/python3.7/zipfile.py", line 1428, in read
    with self.open(name, "r", pwd) as fp:
  File "/usr/lib/python3.7/zipfile.py", line 1480, in open
    self._fpclose, self._lock, lambda: self._writing)
  File "/usr/lib/python3.7/zipfile.py", line 722, in __init__
    self.seekable = file.seekable
AttributeError: 'FileUpload' object has no attribute 'seekable'

Adding seekable to the methods list in FileUpload.__init__ is enough to make the error go away.

This error does not show up on Python 3.5. I haven't checked Python 3.6 yet.

mgedmin commented 1 month ago

This appears to have regressed in zope.publisher 6.0.0 recently. GitHub Actions show that the tests passed four days ago, but are failing now.

There was a new https://pypi.org/project/multipart/#history release (1.0.0) four days ago, which I don't think is a coincidence.

mgedmin commented 1 month ago

So, the seekable() method disappeared for me because multipart.MultipartPart.file, which is a tempfile.SpooledTemporaryFile since multipart 1.0.0, doesn't have seekable() in Python 3.10 or older, and I'm using 3.8 (because Ubuntu 20.04 LTS).