zopyx
(Andreas Jung)
December 10, 2019, 11:15am
1
Situation: Plone 5.2 with the following test setup (which should create a Folder in the portal root with a contained Document):
folder = plone.api.content.create(
type='Folder',
container=self.portal,
id='folder')
document = plone.api.content.create(
type='Document',
container=self.portal['folder'],
id='document2')
However the Document is created within the Plone root instead of the created Folder:
50 type='Folder',
51 container=self.portal,
52 id='folder')
53
54 import pdb; pdb.set_trace()
55 -> document = plone.api.content.create(
56 type='Document',
57 container=self.portal['folder'],
58 id='document2')
59
60 IUnavailable(folder).unavailable = True
(Pdb) folder
<Item at /plone/folder>
(Pdb) doc = plone.api.content.create(type='Document', container=folder, id='testdoc')
*** AttributeError: __getitem__
(Pdb) folder.aq_parent
<PloneSite at /plone>
(Pdb) folder.aq_parent.objectIds()
['portal_setup' ....., 'folder', 'testdoc']
Bug or feature?
pbauer
(Philip Bauer)
December 10, 2019, 3:18pm
2
It works fine in default Plone 5.2 with a default addon.
espenmn
(Espen)
December 10, 2019, 4:47pm
3
Taken from memory:
myfolder = plone.api.content.create(
type='Folder',
container=self.portal,
id='folder')
document = plone.api.content.create(
type='Document',
container=myfolder,
id='document2')
zopyx
(Andreas Jung)
December 10, 2019, 9:26pm
4
espenmn:
Taken from memory:
..irrelevant...both objects are identical.
espenmn
(Espen)
December 10, 2019, 9:48pm
5
hmmm. I have similar code in a setuphandler where it works. Can not spot any difference… same with this:
https://github.com/espenmn/medialog.bergensiana/blob/master/medialog/bergensiana/setuphandlers.py#L79-L99
fredvd
(Fred van Dijk)
December 12, 2019, 8:47am
6
@zopyx Plone 5.2 ...., in python2 or python3 mode? and which minor version?
zopyx
(Andreas Jung)
December 12, 2019, 9:46am
7
Plone 5.2, Python 3.7.5.
Clearly the invokeFactory()
call is doing something strange..had not time for further debugging.
espenmn
(Espen)
December 16, 2019, 5:47pm
8
Are you sure?
Is
container=self.portal['folder'],
correct syntax (what is self here ), should it not be like
portal = api.portal.get()
…
container=portal['folder'],
zopyx
(Andreas Jung)
December 16, 2019, 6:07pm
9
Sorry but this barely nonsense.
Passing a folder instance as container
is supposed to work.
ramonski
(Ramon Bartl)
December 16, 2019, 8:15pm
10
Hi Andreas,
if you are in a (unit-)test setup, a folder with the ID folder
might already exist (from some test layer). Can you do a self.portal.objectIds()
before you create the folder
to check this or use another ID?
Sometimes I also encounter similar issues in tests when creating new content and need to do an explicit transaction.commit()
after it.
However, neither did I dig any deeper into that code. Maybe you can also do an invokeFactory
instead of plone.api.content.create
to see if the issue remains.
Regards, Ramon
zopyx
(Andreas Jung)
December 17, 2019, 6:13am
11
No. And if there were another folder
then the content would be created inside this folder
but not in the Plone root.
Need to investigate this in 2020 after vacation.
pbauer
(Philip Bauer)
December 17, 2019, 6:53am
12
This is just lazy. Noone can replicate your problem and we all have code like that working fine.
My guess is that your content-type Folder
is itemish and not folderish. For default-Plone with plone.app.contenttypes the __repr__
of the item calles folder
you create at the start of your code should be:
<Folder at /plone/folder>
For you it is
<Item at /plone/folder>
ramonski
(Ramon Bartl)
December 17, 2019, 7:24am
13
No, plone.api
would raise then an error similar to this one:
*** BadRequest: The id "folder" is invalid - it is already in use.
Which could lead to unexpected results in a test setup.
But I think the response from @pbauer is more likely.
Anyhow, more investigation here needed with the actual code and database.