Dexterity and Audio

Well we've started using dexterity on some sites. We've created a nice little HTML5 wrapper for uploaded mp4 audio files. Doing so required really two things, a file field and a transcription field. We ran into a weird issue though. On upload of items when you check create object title from file name you get this:

Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module plone.z3cform.layout, line 70, in __call__
Module plone.z3cform.layout, line 54, in update
Module plone.z3cform.fieldsets.extensible, line 59, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module, line 138, in update
Module z3c.form.action, line 99, in execute
Module z3c.form.button, line 315, in __call__
Module z3c.form.button, line 170, in __call__
Module plone.dexterity.browser.add, line 96, in handleAdd
Module z3c.form.form, line 247, in createAndAdd
Module plone.dexterity.browser.add, line 75, in add
Module plone.dexterity.utils, line 142, in addContentToContainer
Module, line 34, in chooseName
Module zope.component.hooks, line 104, in adapter_hook
Module, line 16, in __new__
Module zope.component.hooks, line 104, in adapter_hook
Module plone.dexterity.primary, line 24, in __init__
TypeError: ('Could not adapt', <Item at >, <InterfaceClass plone.rfc822.interfaces.IPrimaryFieldInfo>)

I couldn't find anything online about this so here we document the quick fix...

Fix this by:

  1. go to ZMI portal_types
  2. modify model source here to add in xmlns:marshal=""
  3. add marshal:primary="true" to namedfile that should be the name of file

Save it.. restart your clients and you should be good to go.

BTW our Behaviors has:

With a model of:

<model xmlns=""
<field marshal:primary="true" name="file" type="plone.namedfile.field.NamedFile" >
<description />
<field name="transcription" type="">
<description>This field is for the transcription text of the media.</description>