Opened 4 years ago

Closed 4 years ago

#15214 closed Cleanup/optimization (duplicate)

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

Reported by: gg Owned by: gg
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 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:3 Changed 4 years ago by prestontimmons

  • Easy pickings unset
  • Resolution set to duplicate
  • Status changed from new to closed
  • 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