#31 — ARFilePreview 2.2.2 w/ Plone 3.3.2 crashes when adding a file

by Gilles Lenfant last modified Nov 07, 2009 12:10 PM
State Unconfirmed
Version: 2.2.0-pre2
Area Functionality
Issue type Bug
Severity Medium
Submitted by Gilles Lenfant
Submitted on Nov 07, 2009
Responsible
Target release:
Hi,

Trying to add a File raises this :

2009-11-07 12:26:16 ERROR Zope.SiteErrorLog 1257593176.680.233580235471 http://localhost:8080/[…]/atct_edit
Traceback (innermost last):
  Module ZPublisher.Publish, line 119, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 42, in call_object
  Module Products.CMFPlone.FactoryTool, line 371, in __call__
  Module Products.CMFPlone.FactoryTool, line 155, in __getitem__
  Module Products.CMFPlone.PloneFolder, line 348, in invokeFactory
  Module Products.CMFCore.TypesTool, line 716, in constructContent
  Module Products.CMFCore.TypesTool, line 276, in constructInstance
  Module Products.CMFCore.TypesTool, line 450, in _constructInstance
  Module Products.ATContentTypes.content.file, line 10, in addATFile
  Module zope.event, line 23, in notify
  Module zope.component.event, line 26, in dispatch
  Module zope.component._api, line 131, in subscribers
  Module zope.component.registry, line 300, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module zope.component.event, line 33, in objectEventNotify
  Module zope.component._api, line 131, in subscribers
  Module zope.component.registry, line 300, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module Products.ARFilePreview.events, line 45, in buildAndStorePreview
  Module Products.ARFilePreview.adapters, line 118, in buildAndStorePreview
AttributeError: 'str' object has no attribute 'filename'


BTW, you should not "print" in a Zope app. Prefer using "logging" module.
Added by Gilles Lenfant on Nov 07, 2009 12:10 PM
I fixed inserting the stuff after line 118 of Products/ARFilePreview/adapters.py

    file_ = self.context.getPrimaryField().getAccessor(self.context)()

    # <patch> (file_ is '' at content creation when a file obj is expected)
    if type(file_) is type(''):
        self.setPreview(u"")
        return
    # </patch>
    data = transforms.convertTo('text/html', self.context.get_data(), filename=file_.filename)

Note I renamed "file" to "file_" just because "file" is a builtin.

No responses can be added.