Re: schema upgrades with zope.formlib + FIX

Johannes Raggam <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <1297777027.8232.8.camel@nano>
... necessary, because when setting fields for an upgraded schema,
applyData tries to get the - inexistent - old value from the field to
compare it against the newvalue.


On Tue, 2011-02-15 at 14:34 +0100, Johannes Raggam wrote:
> well, for schema upgrades, also following patch seems to be necessary:
> 
> 
> >From c11064b8d8a7607d41071250f587f097f8c130a3 Mon Sep 17 00:00:00 2001
> From: Johannes Raggam <[email protected]>
> Date: Tue, 15 Feb 2011 14:29:56 +0100
> Subject: [PATCH 2/2] gracefully set newvalue for upgraded schemas, where
> oldvalue isn't available.
> 
> ---
>  zope/formlib/form.py |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/zope/formlib/form.py b/zope/formlib/form.py
> index 0d3ade3..ff10168 100755
> --- a/zope/formlib/form.py
> +++ b/zope/formlib/form.py
> @@ -532,7 +532,13 @@ def applyData(context, form_fields, data,
> adapters=None):
>  
>          name = form_field.__name__
>          newvalue = data.get(name, form_field) # using form_field as
> marker
> -        if (newvalue is not form_field) and (field.get(adapter) !=
> newvalue):
> +        try:
> +            oldvalue = field.get(adapter)
> +        except AttributeError:
> +            # value not available after schema upgrade
> +            # make sure that oldvalue != newwalue
> +            oldvalue = not bool(newvalue)
> +        if (newvalue is not form_field) and (oldvalue != newvalue):
>              descriptions.setdefault(interface,
> []).append(field.__name__)
>              field.set(adapter, newvalue)
>  
> -- 
> 1.7.1
> 
> 
> On Tue, 2011-02-15 at 13:25 +0100, Hanno Schlichting wrote:
> > On Tue, Feb 15, 2011 at 1:21 PM, Johannes Raggam <[email protected]> wrote:
> > > while - IMO - zope.schema throws that error justifiably, i think
> > > zope.formlib should handle it more gracefully in setUpEditWidgets. i
> > > think, this error comes with every schema upgrade for zope.formlib based
> > > edit-forms. so, what do you think of following patch?
> > 
> > The usual approach is to add new attributes as class attributes to the
> > persistent object. Or write an actual database upgrade step, either
> > via something like zope.generations or with a GenericSetup upgrade
> > step.
> > 
> > But for zope.formlib it make indeed make sense to be more lenient
> > here. So +0 on your patch.
> > 
> > Hanno
> 

-- 
johannes raggam / thet
python plone zope development
http://johannes.raggam.co.at/
mailto:[email protected]
http://bluedynamics.com/

-- 
johannes raggam / thet
python plone zope development
http://johannes.raggam.co.at/
mailto:[email protected]
http://bluedynamics.com/

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.