KeyError on Linking to a File object (*Not* a Plone 4 to 5 migration issue)

I saw the KeyError topics relating to migration from Plone 4.3 to 5. However, I got something similar that did not involve a migration. In this case, when I link to a file using the link button in a RichText edit area (on a Page object), I get the following KeyError.

The link is correct (and the File object exists with that URL and filename), so I'm at a loss to know why a KeyError is thrown.

Here is the traceback...

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.z3cform.layout, line 66, in call
Module plone.z3cform.layout, line 50, in update
Module plone.dexterity.browser.edit, line 58, in update
Module plone.z3cform.fieldsets.extensible, line 59, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module z3c.form.group, line 145, in update
Module plone.app.z3cform.csrf, line 21, in execute
Module z3c.form.action, line 98, in execute
Module z3c.form.button, line 315, in call
Module z3c.form.button, line 170, in call
Module plone.dexterity.browser.edit, line 30, in handleApply
Module z3c.form.group, line 126, in applyChanges
Module zope.event, line 31, in notify
Module zope.component.event, line 24, in dispatch
Module zope.component._api, line 136, in subscribers
Module zope.component.registry, line 321, in subscribers
Module zope.interface.adapter, line 585, in subscribers
Module zope.component.event, line 32, in objectEventNotify
Module zope.component._api, line 136, in subscribers
Module zope.component.registry, line 321, in subscribers
Module zope.interface.adapter, line 585, in subscribers
Module plone.app.linkintegrity.handlers, line 100, in modifiedContent
Module plone.app.linkintegrity.handlers, line 87, in getObjectsFromLinks
Module five.intid.intid, line 41, in getId
Module zope.intid, line 89, in getId
KeyError: <File at /texasbusinesslaw/research-resources/texas-business-law-journal/volume-46/2015business-law-journal_finalpdf.pdf>

Disregard. It is specific to a particular instance of Plone. I wasn't able to duplicate this problem on another instance of Plone 5. I think the problem is from the Apache2 proxy settings, although those seem to be working well.

Hi, i have a similar problem randomly, in a Plone 4.3 dexterity content and also on some Plone 5 base contents.

Sometimes when i try to reference an object with reference fields, i have the same error:
a KeyError on zope.intid.

It seems that the object that i want to reference isn't correctly indexed in intid catalog, and when i try to create a reference to it, it breaks like this.

Sometimes i also have a problem like ronc's one: when i try to delete a content, i get the same KeyError from linkintegrity.

The question is: how is it possible that sometimes some contents isn't indexed in the intid catalog (apparently) randomly? I have this kind of problems on different Plones (4.3 and 5.1) and different content-types (base and custom).

P.S.: this "problem" has a simple but ugly solution: editing and saving the broken object, will index it correctly. Is there a way to make a clean and rebuild on this catalog?

Yes, you can do that in the catalog, I think the URL will be http://yoursite.com//portal_catalog/manage_catalogAdvanced

I think that it's something related to the intid catalog, not with the portal_catalog..am i wrong?
The missing index is in intid. portal_catalog is fine

Ok, digging in the code, the solution is simple: i need to call the register method on my not indexed contents.

As i see, this method is called from an event handler in five.intid on "zope.lifecycleevent.interfaces.IObjectAddedEvent"..it seems that for some reason, sometimes this event isn't fired (strange because the content shouldn't be in the catalog too) or exits in some conditions.

1 Like

Event handling is not always robust: if some event handler raises an exception, the result may surprise (as some handlers may not be executed). Usually, the exception results in a transaction abort (and then the complete transaction has no effect). However, when application code catches the exception, an inconsistent persistent state may result. This often affects deletion (where the exception is catched to ensure the an object can be deleted (by sufficiently priviledged users). I do not know about an exception catching during creation.