[Zope] OFS/Image.py strange error
Vladimir Petrovic
vladap at criticalpublics.com
Wed Oct 8 07:47:17 EDT 2003
Hi,
I'm getting a very strange error during the development of my python based
product. The error occurs only in one specific case, and the setup is quite
complicated. The error happens inside Zope code, so I'm looking for hints how
to proceed with debuging. The issue is that during a call to _read_data () in
OFS/Image.py I get the following error:
KeyError: validate
Traceback:
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 135, in __call__
However, the actual _read_data () happens inside the python product, so the
original traceback is somehow lost.
Here is the setup:
I have a python product which defines a class that inherits ObjectManager
(called Content). I have another classes DRFile/DRImage which inherit Zope's
File/Image.
Inside manage_addContent (), manage_addDRFIle () is called to create
automatically new DRFile inside content:
manage_addContent ():
co = Content (id)
self._setObject (id, co)
co = self._getOb (id)
co.add_part_web (default_part_id, default_part)
add_part_web (pid, pdata):
nid, title = get_default_id_title_for_file (pid, '', pdata)
manage_addDRFile (self, id=nid, title=title, file=pdata)
manage_addDRFile ():
o = DRFile (id, title, '')
self._setObject (id, o)
if file:
o = self._getOb (id)
file_upload (o, file)
Now file_upload (o, file) is the problem. It used to contain just:
obj.manage_upload (file)
But this line was generating the error. If I put raise 'ABC' just before, I
get the 'ABC' exception, but if I put it just after I get this KeyError.
I've managed to avoid this exception with:
file_str = file.read ()
data, size = obj._read_data (file_str)
content_type = obj._get_content_type (file, data,
obj.__name__, 'application/octet-stream')
obj.update_data (data, content_type, size)
This is exactly the code from mange_upload () from Image.py, except string is
passed (file.read ()) to _read_data () instead of actual FileUpload object.
This error happens only in one specific case. I can upload the file manually
through Zope management interface. I can also upload many other files without
any problem. I could imagine something is wrong with FileUpload object, but I
don't know how to proceed with the debugging because I don't know how it is
possible that _read_data () produces the traceback which doesn't have
anything in common with the way it is called ?
Thanks in advance,
Vladimir
More information about the Zope
mailing list