Was scratching my head for a bit today before finding out what I had done wrong... Maybe this will help someone, and maybe a different error message "Hey dimwit, tokens must be ascii!" would have made me look in the right direction somewhat faster.
What had happened is that I unknowingly passed an INT to look for a term in my vocabulary. This resulted in the following Traceback:
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
Module ZPublisher.WSGIPublisher, line 376, in publish_module
Module ZPublisher.WSGIPublisher, line 271, in publish
Module ZPublisher.mapply, line 85, in mapply
Module ZPublisher.WSGIPublisher, line 68, in call_object
Module pnz.erpediem.core.browser.invoice, line 50, in __call__
Module plone.autoform.view, line 42, in __call__
Module plone.autoform.view, line 33, in render
Module Products.Five.browser.pagetemplatefile, line 126, in __call__
Module Products.Five.browser.pagetemplatefile, line 58, in __call__
Module zope.pagetemplate.pagetemplate, line 133, in pt_render
Module Products.PageTemplates.engine, line 365, in __call__
Module z3c.pt.pagetemplate, line 176, in render
Module chameleon.zpt.template, line 302, in render
Module chameleon.template, line 215, in render
Module chameleon.utils, line 53, in raise_with_traceback
Module chameleon.template, line 192, in render
Module c0fc417e90455b08c29fb58c91916011, line 469, in render
Module c39cf845968cb86048645198670b6234, line 428, in render_master
Module zope.contentprovider.tales, line 76, in __call__
Module zope.viewlet.manager, line 157, in update
Module zope.viewlet.manager, line 163, in _updateViewlets
Module plone.app.layout.viewlets.common, line 142, in update
Module plone.memoize.view, line 59, in memogetter
Module plone.app.layout.viewlets.common, line 129, in page_title
Module plone.memoize.view, line 59, in memogetter
Module plone.app.layout.globals.context, line 145, in object_title
Module plone.base.utils, line 183, in pretty_title_or_id
Module pnz.erpediem.core.trajects.invoice, line 57, in Title
Module zope.schema.vocabulary, line 196, in getTerm
LookupError: 380
My invoice was supposed to show a Title based on the contents of the vocabulary:
def Title(self):
vocabulary = BGMDocumentCodesVocabulary(context=None)
document_type = self._object.document_type
document_type_title = translate(vocabulary.getTerm(document_type).title, context=getRequest())
return u'%s (%s)' % (self._object.invoice_id, document_type_title)
Now, looking in my Vocabulary, I did find the value "380" and my SQLAlchemy-based CT object clearly used
document_type = Column(
types.Unicode(3),
default=null(),
)
But of course, that code only matters when writing to MySQL...
Cause of the problem: in my MySQL database schema, I had stupidly defined the document_type column as an INT, so I received an INT and Plone barfed...
Knowing that Plone coerces tokens to always be ascii when writing them, shouldn't there have been some kind of sanity check in zope.schema.vocabulary to prevent me from passing on something else than an ascii string?