Re: [Zope3-Users] z3c.form: LookupErrors

2009-04-08 Thread Martin Aspeli
Stephan Richter wrote:
 On Wednesday 08 April 2009, Martin Aspeli wrote:
 What I'd like to see:

   1) z3c.form catches the LookupError and treats it as a valdiation
 error (even on first render of the form), not a fatal error

   2) z3c.form defaults to missing_value if there is a LookupError
 against what the data manager returns. The value is indeed missing in
 action

   3) If possible, we output the offending value in the error message

   4) In use cases where it makes sense, people can use a field property
 implementation that checks the source and returns the default (or
 something else) if the value can't be found. That's not for z3c.form
 to decide or depend on though.
 
 Sounds good.

Would you mind making a 1.9 maintenance branch and, if we fix a few 
bugs, could you release 1.9.1 soonishly.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] z3c.form: LookupErrors

2009-04-07 Thread Martin Aspeli
Hi,

In z3c.form (at least with 1.9.0), if you have a Choice field and the 
vocabulary changes so that an existing value (or the default value on an 
add form) is no longer valid, you get a LookupError:

   Module z3c.form.form, line 126, in updateWidgets
   Module z3c.form.field, line 259, in update
   Module z3c.form.browser.select, line 51, in update
   Module z3c.form.browser.widget, line 61, in update
   Module z3c.form.widget, line 182, in update
   Module z3c.form.widget, line 120, in update
   Module z3c.form.converter, line 258, in toWidgetValue
   Module z3c.form.term, line 31, in getTerm
   Module zope.schema.vocabulary, line 124, in getTerm

It'd be nicer if z3c.form would catch the error and return 
field.missing_value or something like that. As it stands, if this 
happens with a content object, it's impossible to reach the edit form 
and fix the value!

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.form: LookupErrors

2009-04-07 Thread Roger Ineichen
Hi Martin


 -Ursprüngliche Nachricht-
 Von: zope3-users-boun...@zope.org 
 [mailto:zope3-users-boun...@zope.org] Im Auftrag von Martin Aspeli
 Gesendet: Dienstag, 7. April 2009 16:17
 An: zope3-users@zope.org
 Betreff: [Zope3-Users] z3c.form: LookupErrors
 
 Hi,
 
 In z3c.form (at least with 1.9.0), if you have a Choice field 
 and the vocabulary changes so that an existing value (or the 
 default value on an add form) is no longer valid, you get a 
 LookupError:
 
Module z3c.form.form, line 126, in updateWidgets
Module z3c.form.field, line 259, in update
Module z3c.form.browser.select, line 51, in update
Module z3c.form.browser.widget, line 61, in update
Module z3c.form.widget, line 182, in update
Module z3c.form.widget, line 120, in update
Module z3c.form.converter, line 258, in toWidgetValue
Module z3c.form.term, line 31, in getTerm
Module zope.schema.vocabulary, line 124, in getTerm
 
 It'd be nicer if z3c.form would catch the error and return 
 field.missing_value or something like that. As it stands, if 
 this happens with a content object, it's impossible to reach 
 the edit form and fix the value!

This is a legacy data problem. Such data need to get migrated
by a generation if a value is no longer valid.

Otherwise the wrong (not valid) value is still used in the app.
It doesn't make sense to just skip invalid values and fallback
to missing_value in the vocabulary widget since this value get
used by everthing else then the widget.

But probably if legacy data are not a problem in some apps,
we should implement a vocabulary and widget which can handle
such legacy data problems or make it a configurable option.

I also was thinking about a widget which allows to define
depreated values which are valid but not shown for selecting.
this whould allow to skip values fer a future selection.
Probably this whould require a enhanced vocabulary implementation
which offers a deprecated value list or something like that.

What do you think? Whould this fit for you?

Regards
Roger Ineichen

 Martin
 
 --
 Author of `Professional Plone Development`, a book for 
 developers who want to work with Plone. See 
 http://martinaspeli.net/plone-book
 
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users
 

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.form: LookupErrors

2009-04-07 Thread Stephan Richter
On Tuesday 07 April 2009, Roger Ineichen wrote:
  It'd be nicer if z3c.form would catch the error and return
  field.missing_value or something like that. As it stands, if
  this happens with a content object, it's impossible to reach
  the edit form and fix the value!

 This is a legacy data problem. Such data need to get migrated
 by a generation if a value is no longer valid.

No, it is not. The legacy data problem is a special case.

What if your list of choices depends on constantly changing data? For example, 
a widget allows you to select a user from a userfolder. Later the user gets 
deleted. Just because you selected the user before, the form should not fail.

I totally agree with Martin that we should use missing_value in those cases.

I think this could actually be considered a fairly serious bug.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. Zope Stephan Richter
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.form: LookupErrors

2009-04-07 Thread Roger Ineichen
Hi Stephan

 -Ursprüngliche Nachricht-
 Von: Stephan Richter [mailto:srich...@cosmos.phy.tufts.edu] 
 Gesendet: Dienstag, 7. April 2009 19:30
 An: zope3-users@zope.org; d...@projekt01.ch
 Cc: 'Martin Aspeli'
 Betreff: Re: [Zope3-Users] z3c.form: LookupErrors
 
 On Tuesday 07 April 2009, Roger Ineichen wrote:
   It'd be nicer if z3c.form would catch the error and return 
   field.missing_value or something like that. As it stands, if this 
   happens with a content object, it's impossible to reach the edit 
   form and fix the value!
 
  This is a legacy data problem. Such data need to get migrated by a 
  generation if a value is no longer valid.
 
 No, it is not. The legacy data problem is a special case.
 
 What if your list of choices depends on constantly changing 
 data? For example, a widget allows you to select a user from 
 a userfolder. Later the user gets deleted. 

pang, legacy data created

 Just because you 
 selected the user before, the form should not fail.

and the question is, do you cleanup legacy data or not

 I totally agree with Martin that we should use missing_value 
 in those cases.

Defently not. Such forms will show you a default value and you
think this is Ok. But the object devliers still the old
stored value. Pang, pang and you will be surprised till you 
will start debugging and see the real value decorated within the
missing_value. That's a horrible scenario!

 I think this could actually be considered a fairly serious bug.

No, defently not, the Choice field defines what are valid values
and the widget only handels that. There is no reason why a widget
should do more then that.

If you remove valid values for a field, you also have to make
sure that the system doesn't use them. Doesn't matter if a 
system can work with different/legacy data or not.

I think you are right that a valid missing_value should get
used, but that must be implemented at the field level. The 
field has to return that missing_value. This will make sure
that objects value returns the same as the widget does.

But that's a kind of auto-mirgation for legacy data.
And I'm not sure if this is a good idea.

Regards
Roger Ineichen

 Regards,
 Stephan
 --
 Stephan Richter
 Web Software Design, Development and Training Google me. 
 Zope Stephan Richter
 

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users