Opened 18 years ago

Last modified 17 years ago

#3489 closed

Altering self.fields in Form.__init__() fails — at Version 1

Reported by: Ronny Pfannschmidt <ronny.pfannschmidt@…> Owned by: nobody
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

take a look at the test

"""
>>> TestForm({'text':"foo"}).is_valid()
True

>>> TestForm({'text':"foo"},need_name=True).is_valid()
False

>>> TestForm({'text':"foo"}).is_valid() #this one will fail
True

"""
from django.newforms import *
class TestForm(Form):
    name = CharField(max_length=30)
    text = CharField(widget=Textarea)
    def __init__(self,*k,**kw):
        need_name=kw.pop("need_name",False)
        Form.__init__(self,*k,**kw)

        if need_name:
            self.fields["name"].required=True

Just assigning need_name to self.fields["name"].required would create a race condition for multithreaded servers.

Change History (1)

comment:1 by Adrian Holovaty, 18 years ago

Description: modified (diff)
Summary: altering local newforms Formfields fails cause self.fields isnt a deep copyAltering self.fields in Form.__init__() fails
Triage Stage: UnreviewedAccepted

Fixed formatting in description.

Note: See TracTickets for help on using tickets.
Back to Top