Opened 14 years ago
Closed 13 years ago
#15912 closed Cleanup/optimization (fixed)
CharField.widget_attrs should respect its super
Reported by: | Ruy Asan | Owned by: | mmcnickle |
---|---|---|---|
Component: | Forms | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | mathieu.agopian@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The contract of the Field.widget_attrs method is that it returns a dictionary (even says so in the docstring), however CharField.widget_attrs may return None (when the if clause fails). It should at least return an empty dict, or better yet, simply modify whatever the super-method returns.
Attachments (3)
Change History (8)
comment:1 by , 14 years ago
Cc: | added |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
Component: | File uploads/storage → Forms |
---|
comment:3 by , 13 years ago
Needs tests: | unset |
---|---|
Owner: | changed from | to
Patch needs improvement: | unset |
Status: | new → assigned |
The attached patch makes sure widget_attrs() always returns a dictionary, even if it's empty.
I didn't think that the super call was necessary as Field only returns an empty dictionary by default. If this ever changes, then we can add the super call then.
by , 13 years ago
Attachment: | 15912.diff added |
---|
Make sure CharField? always returns a dictionary from widget_attrs()
comment:4 by , 13 years ago
UI/UX: | unset |
---|
The patch and test look good. I added a slightly modified patch to fix a typo, added a reference to this ticket, and remove a redundant test in15912.2.diff.
Also attached a version using a super call for the committers disgression.
Hello rubyruy,
Thanks for the feedback, and indeed, i believe
django.forms.fields.CharField.widget_attrs
should return a dictionary in all cases, as written indjango.forms.fields.Field.widget_attrs
, but even more, it should return an updated dict from it.I'm thus marking this ticket as accepted, but i also added the "needs tests" and "patch needs improvement" flags.
Regarding the improvements, you use
attrs.setdefault
, while it should rather be usingattrs.update
: child's attributes should have precedence.As a side note, the github django repository is only a mirror, the official repository is on SVN (on this very track). Thus the pull request won't be accepted on github. Also, please attach the patch (with tests if possible, that would be brilliant) to this ticket, as it'll ease the review and everybody's work!