Opened 18 years ago

Closed 18 years ago

#2899 closed defect (fixed)

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

Reported by: john@… Owned by: Adrian Holovaty
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: no UI/UX: no

Description

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@… 18 years ago.
Patch for ticket #2899
formwrapper_defaults.2.diff (831 bytes ) - added by john@… 18 years ago.
New version of [patch] with changes suggested by adurdin

Download all attachments as: .zip

Change History (5)

by john@…, 18 years ago

Attachment: formwrapper_defaults.diff added

Patch for ticket #2899

comment:1 by adurdin@…, 18 years ago

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, self.data = manipulator, (data or {})
    self.error_dict = error_dict or {}

by john@…, 18 years ago

Attachment: formwrapper_defaults.2.diff added

New version of [patch] with changes suggested by adurdin

comment:2 by Bastian Kleineidam <calvin@…>, 18 years ago

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 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

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

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