zopyx
(Andreas Jung)
October 14, 2019, 12:16pm
1
A customer site has collection portlet with an assignment where I am trying to resolve the reference to target collection
(Pdb) assignment
<ugent.portlet.collection.portlet.UGentCollectionAssignment object at 0x7fdc17c92a28>
The target_collection
value raises an error upon to_object
:
(Pdb) assignment.__dict__
{'target_collection': <z3c.relationfield.relation.RelationValue object at 0x7fdc17c92aa0>, '__annotations__': <BTrees.OOBTree.OOBTree object at 0x7fdc17c89850>, 'random': False, 'exclude_context': True, 'show_more': True, 'header': u'News about Ufora', 'limit': 4, 'show_more_text': u'More news ...', '__name__': u'nieuws-over-ufora', '__parent__': <PortletAssignmentMapping at ++contextportlets++plone.rightcolumn>, 'show_dates': False}
(Pdb) assignment.target_collection
<z3c.relationfield.relation.RelationValue object at 0x7fdc17c92aa0>
(Pdb) assignment.target_collection.to_object
*** ComponentLookupError: (<InterfaceClass zope.intid.interfaces.IIntIds>, '')
However there the to_id
value available:
(Pdb) assignment.target_collection.__dict__
{'to_id': 1608143906, 'from_attribute': None, '__parent__': None}
Any idea how to resolve the id -> object?
pbauer
(Philip Bauer)
October 14, 2019, 2:34pm
2
Obviously getUtility(IIntIds)
does not find the IntId-catalog in your site. That happens when plone.app.intid
is not installed or was uninstalled. You could also run the code in:
obj = brain.getObject()
intids.register(obj)
registered += 1
except (AttributeError, KeyError, TypeError):
# "TypeError" happens on a "could not adapt" - this may happen
# for some contenttypes and must not stop this from working.
logger.exception(brain.getURL())
return registered, existing
def add_intids(context):
addUtility(context, IIntIds, IntIds, ofs_name='intids',
findroot=False)
def installIntIds(context):
if context.readDataFile('install_intids.txt') is None:
return
portal = context.getSite()
add_intids(portal)
return 'Added intid utility.'
zopyx
(Andreas Jung)
October 15, 2019, 7:38am
3
plone.app.intid
was actually installed. Just the standard
from zope.component.hooks import setSite
portal = app.plone_portal
setSite(portal)
was missing .
pbauer
(Philip Bauer)
October 16, 2019, 7:28am
4
Then you should probaby have stated that you code was from a script and not code run from within the application...
zopyx
(Andreas Jung)
October 16, 2019, 8:25am
5
Shit happens when you're in panic