Prior to 10206, the formset is_valid returned False and the user saw
the error messages as I intended. From 10206 on, the formset is_valid
returns True (because validation errors on forms marked for deletion
"don't count") and so my view goes on to try to save the forms.
So, is this an unintended consequence? If so, please can it be backed
out pending further design discussion?
No, we really can't. Having an option for every single possibility isn't
a good idea. It leads to option explosion and a very necessary
implementation ("happens to be technically possible" doesn't mean
"actually possible in practice", since it's not practical).
There's usually one predominantly correct behaviour in situations like
this. the fact that some people sometimes don't want that isn't a reason
to add Yet Another Option -- after all, they're not obligated to use
formsets or the admin or anything like that, so they already have a
choice to just use plain Python if they really want something else. In
this case, it sounds like people are using an implementation side-effect
to do something unintended and whilst Joseph's efforts to work with that
for a few weeks longer are admirable, long-term it's a problem that we
should solve with a proper API if the use-case is reasonable (which it
seems like it does). Preserving the undesired side-effect isn't a good
technical approach.
I agree with Joseph here that validation errors shouldn't stop deletion,
since you've said you want to *delete* the form and the data no longer
has a meaning. Data that is about to cease to exist shouldn't play a
role in validation -- it's un-data; wouldn't voom is you put 50,000
volts through it, etc.
The optional piece here is allowing for a form to be prevented from
deletion in the first place, not post hoc.
Malcolm
On Sun, 2009-04-05 at 18:03 -0400, Alex Gaynor wrote:
[...]
> Sure we can have it both ways, how about a constructor option,No, we really can't. Having an option for every single possibility isn't
> "validate_deletions". With the current(that is no validation)
> behavior as the default.
a good idea. It leads to option explosion and a very necessary
implementation ("happens to be technically possible" doesn't mean
"actually possible in practice", since it's not practical).
There's usually one predominantly correct behaviour in situations like
this. the fact that some people sometimes don't want that isn't a reason
to add Yet Another Option -- after all, they're not obligated to use
formsets or the admin or anything like that, so they already have a
choice to just use plain Python if they really want something else. In
this case, it sounds like people are using an implementation side-effect
to do something unintended and whilst Joseph's efforts to work with that
for a few weeks longer are admirable, long-term it's a problem that we
should solve with a proper API if the use-case is reasonable (which it
seems like it does). Preserving the undesired side-effect isn't a good
technical approach.
I agree with Joseph here that validation errors shouldn't stop deletion,
since you've said you want to *delete* the form and the data no longer
has a meaning. Data that is about to cease to exist shouldn't play a
role in validation -- it's un-data; wouldn't voom is you put 50,000
volts through it, etc.
The optional piece here is allowing for a form to be prevented from
deletion in the first place, not post hoc.
Malcolm
No, it's not a false dichotomy. At some level of technical discourse
(and we're certainly there on this list), it's natural to exclude the
obviously poor technical options as already read. This was one of those
cases where providing the option is a fairly clear poor choice (since
it's symptom patching and not making things any better, not problem
solving).
Malcolm
Also the documentation [1] includes code that will no longer work in general:
>>> [form.cleaned_data for form in formset.deleted_forms]
(may fail because form.cleaned_data will not be present if the form
had 'delete' set but other field-level validation errors).
Thinking about possible ways forward, one observation that occurs to
me is that I think there's a significant semantic distinction between
field validation and form-level (non-field) validation that applies in
this case: Field validation errors on forms with delete should not
cause formset is_valid to return False but perhaps form-level errors
should...?
Regards
Dan
It's not clear to me from the thread so far whether there has been a
decision to back out 10206
but, to add some more evidence, I would
point out that it has also made it rather more awkward to process
formsets: You can no longer iterate over form.formsets (e.g. in a save
method) and consider cleaned_data, since it might not be present.
Unless I've missed something, there's deleted_forms, but no analogous
non_deleted_forms (which would help, but may still require quite a lot
of applications to change their approach).
Also the documentation [1] includes code that will no longer work in general:
>>> [form.cleaned_data for form in formset.deleted_forms]
(may fail because form.cleaned_data will not be present if the form
had 'delete' set but other field-level validation errors).
Thinking about possible ways forward, one observation that occurs to
me is that I think there's a significant semantic distinction between
field validation and form-level (non-field) validation that applies in
this case: Field validation errors on forms with delete should not
cause formset is_valid to return False but perhaps form-level errors
should...?