Newforms is_bound determination (was Re: Is it a bug: f.data = data return False instead of True ?)

0 views
Skip to first unread message

Benjamin Slavin

unread,
Jun 1, 2007, 9:51:39 AM6/1/07
to django...@googlegroups.com, Django developers
On 6/1/07, olive <ocol...@gmail.com> wrote:
> This returns True:
> f = myform(data)
> f.is_valid()
>
> while this returns False:
> f = myform()
> f.data = data
> f.is_valid()
>
> Is it a bug ?

Not sure if it should be called a bug or not.... from a quick look at
the source code (django/newforms/forms.py) it is expected behavior.

When a form is initialize, it determines if it is bound (has data) or
unbound (has no data)
self.is_bound = data is not None

Because you are not providing data when the form is initialized, it
determines that it is unbound and will take a shortcut during
cleaning/validation.

It would be possible to promote is_bound to a Form property to do
on-demand determination of bindedness (?) rather than determining it
at instantiation.

I'm forwarding this to the developers list to see if anyone over there
has any thoughts.

- Ben

Reply all
Reply to author
Forward
0 new messages