Opened 8 years ago

Closed 7 years ago

#2899 closed defect (fixed)

[patch] data and error_dict should have defaults in django.forms.FormWrapper

Reported by: john@… Owned by: adrian
Component: Tools Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In some occations it is useful for data and error_dict to have defaults in django.forms.FormWrapper.

Attachments (2)

formwrapper_defaults.diff (668 bytes) - added by john@… 8 years ago.
Patch for ticket #2899
formwrapper_defaults.2.diff (831 bytes) - added by john@… 8 years ago.
New version of [patch] with changes suggested by adurdin

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by john@…

Patch for ticket #2899

comment:1 Changed 8 years ago by adurdin@…

There's a problem with the patch, John: in Python, default values for parameters are evaluated when the function is created, not when it is executed. Your patch will result in all FormWrappers sharing the same default dictionaries. You should change it to something like:

def __init__(self, manipulator, data=None, error_dict=None, edit_inline=True): 
    self.manipulator, = manipulator, (data or {})
    self.error_dict = error_dict or {}

Changed 8 years ago by john@…

New version of [patch] with changes suggested by adurdin

comment:2 Changed 7 years ago by Bastian Kleineidam <calvin@…>

The a or b thingy in Python is not good for default arguments. If you supply an empty dictionary as argument, it will be replaced silently with another object by the arg or {} expression. The failsafe approach is to manually test for None:

def f (arg=None):
    if arg is None:
        arg = {}

comment:3 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [4029]) Fixed #2899: added defaults for data and error_dict params to FormWrapper. Thanks, john@….

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.