[Product-Developers] Updating schema in dexterity : how to update existing objects

Serge Renfer serge.renfer at gmail.com
Fri Nov 1 07:41:07 UTC 2013


Don't you think when the new attribute is compulsory it can generate an
error in default display view?

I had this problem, but I found a way by adding a migration step where I
generate the new attributes on older objects.

It took me quite some time to figure out that the "default" value of a
field is None if not explicitly mentioned in the schema. Moreover, the
_type attribute of field can also be None (in case of Choice with
vocabulary => where the default has to be mentioned, but I don't know how
to force a _type then?)
I give you my module for you to see what I mean! (it will be on github soon
... on the ageliaco.rd2 project )

See you!
serge





2013/10/31 Steve McMahon <steve at dcn.org>

> By my experience, you'll have no problem with Dexterity's default display
> view, which should display the default value if an attribute is missing.
> The problem would be with a custom template or other view. If it simply
> assumed that the new attribute was present, you'd get an error where it
> wasn't.
>
>
> On Thu, Oct 31, 2013 at 9:00 AM, Serge Renfer <serge.renfer at gmail.com>wrote:
>
>> Thank you for your answer!
>>
>> This means, that default view form will check if the property is present
>> before trying to show it and :
>>
>>    - either won't show anything if it's an old object (without that
>>    property, from the previous schema)
>>    - or generating the default value for it for that object
>>
>> Or is it that I have to override the default view to have my own template
>> that check properties on the object to show only the ones this object has?
>>
>> Thanks!
>> serge
>>
>>
>> 2013/10/31 Steve McMahon <steve at dcn.org>
>>
>>> The basic answer is that you typically don't need to worry about it
>>> beyond making sure you set a reasonable default in the declaration.
>>>
>>> After that, the only thing you really need to do is have some defensive
>>> coding in anything that tries to use the attribute (like a template) to do
>>> something reasonable if its absent.
>>>
>>>
>>> On Thu, Oct 31, 2013 at 12:51 AM, Serge Renfer <serge.renfer at gmail.com>wrote:
>>>
>>>> Hello,
>>>>
>>>> I've been searching for doc on how to update existing objects when for
>>>> example you add a property in dexterity interface!
>>>>
>>>> I'm quite sure a doc exists on that matter, but I can't get a hold on
>>>> it!
>>>>
>>>> If any of you could give me pointers on that!
>>>>
>>>> Thanks!
>>>> serge
>>>>
>>>> _______________________________________________
>>>> Product-Developers mailing list
>>>> Product-Developers at lists.plone.org
>>>> https://lists.plone.org/mailman/listinfo/plone-product-developers
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Product-Developers mailing list
>>> Product-Developers at lists.plone.org
>>> https://lists.plone.org/mailman/listinfo/plone-product-developers
>>>
>>>
>>
>
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> https://lists.plone.org/mailman/listinfo/plone-product-developers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20131101/4855ff48/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: upgrades.py
Type: text/x-python-script
Size: 2339 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20131101/4855ff48/attachment-0001.bin>


More information about the Product-Developers mailing list