I have a relation field defined as follows:
application = RelationChoice(
title="Application",
vocabulary="service.app.CompletedApplications",
required=False,
)
And an index set as:
type: FieldIndex
name: application
indexed attribute: application
Since the catalog will index relation values by default, I have a custom indexer which returns the UUID of the target object.
This works. However, when I add another content type with a field defined the same as above, I get the error below:
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 187, in transaction_pubevents
Module transaction._manager, line 255, in commit
Module transaction._manager, line 132, in commit
Module transaction._transaction, line 267, in commit
Module transaction._transaction, line 333, in _callBeforeCommitHooks
Module transaction._transaction, line 372, in _call_hooks
Module Products.CMFCore.indexing, line 317, in before_commit
Module Products.CMFCore.indexing, line 227, in process
Module Products.CMFCore.indexing, line 49, in reindex
Module Products.CMFCore.CatalogTool, line 368, in _reindexObject
Module Products.CMFPlone.CatalogTool, line 320, in catalog_object
Module Products.ZCatalog.ZCatalog, line 495, in catalog_object
Module Products.ZCatalog.Catalog, line 362, in catalogObject
Module Products.PluginIndexes.unindex, line 237, in index_object
Module Products.PluginIndexes.unindex, line 282, in _index_object
Module Products.PluginIndexes.unindex, line 213, in insertForwardIndexEntry
Module functools, line 91, in _gt_from_lt
Module z3c.relationfield.relation, line 91, in __lt__
AttributeError: 'str' object has no attribute 'from_attribute'
Looking at the source code of z3c.relationfield, the error occurred because in line 89:
84 def __lt__(self, other):
89 if (self.from_attribute or '') < (other.from_attribute or ''):
"self" is a RelationValue object, while "other" is the UUID value of the target object. The UUID string does not have a from_attribute method, hence the error.
I am not sure if this is a bug. My work around is to redefine my index as follows:
type: FieldIndex
name: application_uid
indexed attribute: application_uid
So far this seems to work. The field id and index name are different. Is this correct? Or is there a better way to index the UUID of RelationValue fields?