plone / plone.api

The Plone API
https://6.docs.plone.org/plone.api
Other
89 stars 54 forks source link

Use createContentInContainer for Dexterity instead of invokeFactory in plone.api.content.create #318

Open idgserpro opened 8 years ago

idgserpro commented 8 years ago

I have a Dexterity content that has a subscribe that creates a parent to content and move the content to this parent. When I try to use:

compromisso = api.content.create(container,'Compromisso',**dados)

I get error:

...
File "/home/user/sites/brasil.gov.integracaocaldav/src/brasil/gov/integracaocaldav/tests/utils.py", line 84, in cria_compromisso
    **dados)
  File "<string>", line 2, in create
  File "/home/user/cache-python/eggs/plone.api-1.5-py2.7.egg/plone/api/validation.py", line 70, in wrapped
    return f(*args, **kwargs)
  File "<string>", line 2, in create
  File "/home/user/cache-python/eggs/plone.api-1.5-py2.7.egg/plone/api/validation.py", line 131, in wrapped
    return f(*args, **kwargs)
  File "/home/user/cache-python/eggs/plone.api-1.5-py2.7.egg/plone/api/content.py", line 88, in create
    container.invokeFactory(type, content_id, **kwargs)
  File "/home/user/cache-python/eggs/plone.dexterity-2.2.7-py2.7.egg/plone/dexterity/content.py", line 711, in invokeFactory
    type_name, id, RESPONSE, *args, **kw
  File "/home/user/cache-python/eggs/Products.CMFCore-2.2.9-py2.7.egg/Products/CMFCore/PortalFolder.py", line 292, in invokeFactory
    return pt.constructContent(type_name, self, id, RESPONSE, *args, **kw)
  File "/home/user/cache-python/eggs/Products.CMFCore-2.2.9-py2.7.egg/Products/CMFCore/TypesTool.py", line 833, in constructContent
    ob = info.constructInstance(container, id, *args, **kw)
  File "/home/user/cache-python/eggs/Products.CMFCore-2.2.9-py2.7.egg/Products/CMFCore/TypesTool.py", line 311, in constructInstance
    return self._constructInstance(container, id, *args, **kw)
  File "/home/user/cache-python/eggs/Products.CMFCore-2.2.9-py2.7.egg/Products/CMFCore/TypesTool.py", line 571, in _constructInstance
    obj = container._getOb(newid)
  File "/home/user/cache-python/eggs/plone.folder-1.0.8-py2.7.egg/plone/folder/ordered.py", line 58, in _getOb
    raise AttributeError(e)
AttributeError: '12170352'

This error occurs in plone.api.content.create in the call of invokeFactory

When I use:

from plone.dexterity.utils import createContentInContainer
compromisso = createContentInContainer(container,
                                       'Compromisso',
                                       **dados)

worked.

It would not be appropriate to use createContentInContainer for Dexterity content?

idgserpro commented 8 years ago

CC @hvelarde