plone / plone.api

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

`plone.api.content.get(path)` returns a field if it finds one #487

Closed sneridagh closed 2 years ago

sneridagh commented 2 years ago

Given a path like:

path = '/de/examples/blocks

and no content named blocks, it will get and return the blocks field content, because of restrictedTraverse...

Since plone.api.content.get promises to return a content type, we should not return anything that it's not.

ericof commented 2 years ago

@mauritsvanrees, @pbauer Considering the 2.0x branch only targets Python 3, I'm considering checking if the returned value is an instance of Dexterity, if it is not an instance, return None. Any objections?

ale-rt commented 2 years ago

I see the issue, +1 on removing this "buggy feature". What about checking if the object found provides the Products.CMFCore.interfaces.IContentish interface?

sneridagh commented 2 years ago

btw, while I was debugging this further, I've found something I was not aware of... turns out that Zope does not allow you to create a child content object with the same name as a parent DX field name.

Do we have this fact documented?

eg. I can't create a content with blocks id inside anything.

ale-rt commented 2 years ago

IDK where it is documented but I am pretty sure that it is related to the implementation of parent._checkId.

mauritsvanrees commented 2 years ago

Discussion Item is not dexterity. Might be contentish. They should be returned I think.