Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceException: Invalid target UID #294

Closed
hvelarde opened this issue Sep 24, 2013 · 2 comments
Closed

ReferenceException: Invalid target UID #294

hvelarde opened this issue Sep 24, 2013 · 2 comments
Labels
Milestone

Comments

@hvelarde
Copy link
Member

when trying to add a cover as a related item of an Archetypes-based item the following error is shown:

2013-09-24 18:45:18 ERROR Zope.SiteErrorLog 1380059118.940.663604880407 http://localhost:8080/Plone/sample.txt/atct_edit
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 Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
  Module Products.CMFFormController.ControllerBase, line 231, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPythonScript, line 107, in __call__
  Module Products.CMFFormController.ControllerBase, line 231, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
  Module Products.CMFFormController.Script, line 145, in __call__
  Module Products.CMFCore.FSPythonScript, line 127, in __call__
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 1, in content_edit
   - <FSControllerPythonScript at /Plone/content_edit used for /Plone/sample.txt>
   - Line 1
  Module Products.CMFCore.FSPythonScript, line 127, in __call__
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 12, in content_edit_impl
   - <FSPythonScript at /Plone/content_edit_impl used for /Plone/sample.txt>
   - Line 12
  Module Products.Archetypes.BaseObject, line 655, in processForm
  Module Products.Archetypes.BaseObject, line 645, in _processForm
   - __traceback_info__: (<ATFile at /Plone/sample.txt>, <Field relatedItems(reference:rw)>, <bound method ATBlob.setRelatedItems of <ATFile at /Plone/sample.txt>>)
  Module Products.Archetypes.utils, line 130, in mapply
  Module Products.Archetypes.ClassGen, line 76, in generatedMutator
  Module Products.Archetypes.Field, line 1987, in set
   - __traceback_info__: (<ATFile at /Plone/sample.txt>, '9e3eb2bcc39a44cc95e7da5629fa7e4b', ['9e3eb2bcc39a44cc95e7da5629fa7e4b', ''], [])
  Module Products.Archetypes.ReferenceEngine, line 309, in addReference
ReferenceException: Invalid target UID
@fredvd
Copy link
Member

fredvd commented Jun 7, 2017

@hvelarde Because this issue came up first when I was searching for the exact same error I'm adding another note here for those who come after me. But in my case I am trying to reference to plone.app.contenttypes DX Document type in a Plone 4 site.

The behaviour you added to the cover content type in 2013 (6fb4bff) adds the option to reference from covers to other objects in the site (plone.app.relationfield.behavior.IRelatedItems). This is still enabled on covers today, but the cover template doesn't expose the related items viewlet at all so I don't think anybody is actively using this.

Maybe(*) that plone.app.relationfield.behavior.IRelatedItems would also fix the UID's, but the behavior that does support referencing from archetypes to Dexterity is plone.app.referenceablebehavior.referenceable.IReferenceable .

Activating this on Dexterity items doesn't fix existing content though, only if you edit items the UID is stored. Clearing and rebuilding the portal_catalog doesn't work, because the uid_catalog is where the UID's are missing from for dexterity items. @mauritsvanrees documented this in 2010 in a mailinglist thread here, upgrade step listed at the end of this note:
https://groups.google.com/forum/#!topic/dexterity-development/wUd5lEWtrFg

The weird thing is on the maybe(*): In my Plone 4 site with Covers and archetypes items I was able to reference to covers from Archetypes content But referencing to p.a.contenttypes DX Document CT that also has the same "plone.app.relationfield.behavior.IRelatedItems" behavior enabled by default still gave me the "ReferenceException: Invalid target UID" error. For collective.cover it seems that something else is fixing the UID reference probem, but I don't think it's the IRelatedItems behavior. Adding this upgrade step solved the problem:


Upgrade step for updating the uid_catalog after adding the referenceablebehavior from Maurits's mailinglist post:

from Products.CMFCore.utils import getToolByName
logger = logging.getLogger('example')

def apply_referenceable_behavior(context):
    # See plone.app.referenceablebehavior.uidcatalog.
    uid_catalog = getToolByName(context, 'uid_catalog')
    portal_catalog = getToolByName(context, 'portal_catalog')
    brains = portal_catalog(
        meta_type=['Dexterity Item', 'Dexterity Container'])
    for brain in brains:
        obj = brain.getObject()
        path = '/'.join(obj.getPhysicalPath())
        logger.info("Applying referenceable behavior for object at path %s",
                    path)
        uid_catalog.catalog_object(obj, path)

@hvelarde
Copy link
Member Author

hvelarde commented Jun 7, 2017

@fredvd do you think is a good idea to remove the dependency on plone.app.relationfield then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants