To avoid an AccessControl.unauthorized.Unauthorized:
error when trying to create content from the interactive console with plone.api
I'm using adopt_user
portal = api.portal.get()
title = "my title"
description = "my file"
with api.env.adopt_user(username="admin"):
obj = api.content.create(container=portal,type="File",title=title,description=description)
I'm getting an error: `AttributeError: 'NoneType' object has no attribute 'URL'
here's the traceback:
>>> with api.env.adopt_user(username="admin"):
... api.content.create(container=portal,type="File",title=title,description=description)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/app/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/validation.py", line 73, in wrapped
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/validation.py", line 149, in wrapped
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/content.py", line 106, in create
content.aq_parent.manage_renameObject(content_id, new_id)
File "/app/lib/python3.11/site-packages/plone/folder/ordered.py", line 194, in manage_renameObject
result = super().manage_renameObject(id, new_id, REQUEST)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/OFS/CopySupport.py", line 394, in manage_renameObject
notify(ObjectMovedEvent(ob, self, id, self, new_id))
File "/app/lib/python3.11/site-packages/zope/event/__init__.py", line 33, in notify
subscriber(event)
File "/app/lib/python3.11/site-packages/zope/component/event.py", line 27, in dispatch
component_subscribers(event, None)
File "/app/lib/python3.11/site-packages/zope/component/_api.py", line 146, in subscribers
return sitemanager.subscribers(objects, interface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/registry.py", line 445, in subscribers
return self.adapters.subscribers(objects, provided)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/adapter.py", line 896, in subscribers
subscription(*objects)
File "/app/lib/python3.11/site-packages/zope/component/event.py", line 37, in objectEventNotify
component_subscribers((event.object, event), None)
File "/app/lib/python3.11/site-packages/zope/component/_api.py", line 146, in subscribers
return sitemanager.subscribers(objects, interface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/registry.py", line 445, in subscribers
return self.adapters.subscribers(objects, provided)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/adapter.py", line 896, in subscribers
subscription(*objects)
File "/app/lib/python3.11/site-packages/plone/app/caching/purge.py", line 250, in purgeOnMovedOrRemoved
if isPurged(object) and "portal_factory" not in request.URL:
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'URL'
>>> obj = api.content.create(container=portal,type="File",title=title,description=description)
File "<stdin>", line 1
obj = api.content.create(container=portal,type="File",title=title,description=description)
IndentationError: unexpected indent
>>> with api.env.adopt_user(username="admin"):
... obj = api.content.create(container=portal,type="File",title=title,description=description)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/app/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/validation.py", line 73, in wrapped
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/validation.py", line 149, in wrapped
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/plone/api/content.py", line 106, in create
content.aq_parent.manage_renameObject(content_id, new_id)
File "/app/lib/python3.11/site-packages/plone/folder/ordered.py", line 194, in manage_renameObject
result = super().manage_renameObject(id, new_id, REQUEST)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/OFS/CopySupport.py", line 394, in manage_renameObject
notify(ObjectMovedEvent(ob, self, id, self, new_id))
File "/app/lib/python3.11/site-packages/zope/event/__init__.py", line 33, in notify
subscriber(event)
File "/app/lib/python3.11/site-packages/zope/component/event.py", line 27, in dispatch
component_subscribers(event, None)
File "/app/lib/python3.11/site-packages/zope/component/_api.py", line 146, in subscribers
return sitemanager.subscribers(objects, interface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/registry.py", line 445, in subscribers
return self.adapters.subscribers(objects, provided)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/adapter.py", line 896, in subscribers
subscription(*objects)
File "/app/lib/python3.11/site-packages/zope/component/event.py", line 37, in objectEventNotify
component_subscribers((event.object, event), None)
File "/app/lib/python3.11/site-packages/zope/component/_api.py", line 146, in subscribers
return sitemanager.subscribers(objects, interface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/registry.py", line 445, in subscribers
return self.adapters.subscribers(objects, provided)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/lib/python3.11/site-packages/zope/interface/adapter.py", line 896, in subscribers
subscription(*objects)
File "/app/lib/python3.11/site-packages/plone/app/caching/purge.py", line 250, in purgeOnMovedOrRemoved
if isPurged(object) and "portal_factory" not in request.URL:
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'URL'