-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
api.content.create replaces archetype-content title with site title during Plone site creation #99
Comments
Hey @datakurre I'm trying to reproduce this without success. Can you provide more info please:
|
I can confirm the same issue:
here's the code I'm using: SITE_STRUCTURE = (
dict(type='Folder', title=u'One'),
dict(type='Folder', title=u'Two'),
dict(type='Folder', title=u'Three'),
dict(type='Folder', title=u'Four'),
dict(type='Folder', title=u'Five'),
)
def create_new_portal_structure(site):
"""Create new site structure as defined.
"""
logger.info('Creating contet.')
for item in SITE_STRUCTURE:
title = item['title']
id = idnormalizer.normalize(title, 'en')
if not hasattr(site, id):
# by default, the whole structure is excluded from navigation
item['excludeFromNav'] = True
api.content.create(site, **item)
logger.info(u'{0} created'.format(title))
else:
logger.warn(u'skipping {0}; content already exist'.format(title)) I wrote this test to demonstrate the issue: def test_new_portal_structure_titles(self):
"""XXX: plone.api bug: https://github.com/plone/plone.api/issues/99
"""
for item in SITE_STRUCTURE:
title = item['title']
id = idnormalizer.normalize(title, 'en')
self.assertEqual(self.portal[id].title, title) but then it gets worst: test pass but running the code in the instance fails: the title of all items is inherited from the portal: 'Site'. as a workaround I'm using the following: obj = api.content.create(site, **item)
# XXX: following two lines are a workaround for issue in plone.api
# see: https://github.com/plone/plone.api/issues/99
obj.setTitle(title)
obj.reindexObject('Title') |
I get the same problem, but using invokeFactory On Fri, Oct 18, 2013 at 4:34 PM, Héctor Velarde notifications@github.comwrote:
Thomas Desvenain Téléphone : 09 51 37 35 18 |
seems to me this is an Archetypes bug; any reference? |
same issue happens with Dexterity-based content types. I just discovered a new thing: this behavior does not occurs on tests, only when running the instance. |
It seems like the processForm call from api.content.create is an easy but dangerous way to finalise the archetype content, is it will pull any matching field values from the request and override those passed into api.content.create. Can we take what we need from processForm instead (rename after creation and relevant events)? |
What needs to be done, and who is going to do it? |
I am also interested in getting this issue solved. Maybe we could use the |
suggested by pgrunewald
suggested by pgrunewald
The changes introduced in f73bddc breaks content creation when other fields are involved. Consider this usecase: from datetime import datetime
from Products.Archetypes import atapi
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.content import base
from plone import api
class IMyContent(Interface):
""" """
MyContentSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
atapi.DateTimeField(
'date',
schemata='default',
required=True,
languageIndependent=True,
),
)
class MyContent(base.ATCTContent):
implements(IMyContent)
meta_type = 'MyContent'
schema = MyContentSchema
atapi.registerType(MyContent, 'my.package')
def do_manual_creation(context):
fields = {'title': 'A title', 'date': datetime.now()}
content = api.content.create(context, 'MyContent', id='mycontent', **fields)
# pre 1.6.1:
# >>> type(content.date)
# <class 'DateTime.DateTime.DateTime'>
# post 1.6.1
# >>> type(content.date)
# <type 'NoneType'> This is because Pre 1.6.1, I believe a better solution for I will make a pull request, with the change. EDIT: it's actually |
@david-batranu Did you check that the bug with title mentioned above by @datakurre is still fixed ? |
@gotcha you're right! I fixed the pull request, it now uses a |
fix #99 Call processForm with empty values.
How to reproduce:
plone.api.content.create
to create content in "setuphandlers.py" (or custom GS profile configuration step).Then
Each new Archetype-based content object created with plone.api.content.create will have site title as its title.
Why
Our local fix is to pop "title" key from the request.form before running code with plone.api.content.create.
But note that this is not limited to the site creation from but any values in request.form may cause similar surprises with api.content.create.
If it's not a feature to read field values for plone.api.content.create from request, then maybe request.form should somehow be cleared before creating Archetypes-content and restored afterwise.
The text was updated successfully, but these errors were encountered: