Opened 6 years ago

Closed 5 years ago

#15214 closed Cleanup/optimization (duplicate)

CharField's widget_attrs should return an empty dict rather than None

Reported by: Gabriel Grant Owned by: Gabriel Grant
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

See http://code.djangoproject.com/browser/django/trunk/django/forms/fields.py#L217

When self.max_length is None or widget is not a TextInput or PasswordInput instance, no return value is specified.

Returning None can break things when a dict is expected. Theoretically, it should probably call the superclass' widget_attrs and update the dict with its own values (if the conditions are met). In practice, I'm not sure the super call really matters.

Change History (3)

comment:1 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

In practice, this doesn't really matter -- the existing uses of widget_attrs (essentially just in the constructor for a field) check for a null response. However, that check could be removed entirely if CharField did the right thing.

comment:2 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Type: Cleanup/optimization

comment:3 Changed 5 years ago by Preston Timmons

Easy pickings: unset
Resolution: duplicate
Status: newclosed
UI/UX: unset

This is a duplicate of #15912. Closing this one since the other has a patch.

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