#28095 closed Cleanup/optimization (fixed)
Document Widget.build_attrs() signature change in Django 1.11
Reported by: | Melvyn Sopacua | Owned by: | brian houston morrow |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
While build_attrs is undocumented (not sure why, since many widgets override render() and make use of build_attrs) and changed it's method signature in 1.11 by removing kwargs.
This isn't mentioned in the release notes.
A compatibility method could look something like this:
def build_attrs(self, extra_attrs=None, **kwargs): # Django 1.11 changed method signature by removing kwargs if extra_attrs: kwargs.update(extra_attrs) return super().build_attrs(extra_attrs=kwargs)
An update of the release notes would be very welcome.
Change History (8)
comment:1 by , 8 years ago
Summary: | Widget "build_attrs" changed method signature → Document Widget.build_attrs() signature change in Django 1.11 |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
I don't think it should be documented.
The apparent reason for making this backwards-incompatible change was that it was deemed internal (because it was not documented).
However - it is widely used in the field, as Widget.render()
used to be abstract and widget implementors copied code from InputWidget
and friends, which used build_attrs.
But because it is widely used and incompatible, it should be noted in the release notes.
Personally, I expect this method to be removed, as it's nothing more then a wrapper for dict.update()
, with no added value (the fact that you could pass keyword arguments that would be added as attributes was it's added value, as that is much easier to type and read).
comment:5 by , 8 years ago
Okay, that makes sense.
I've removed that part of the commit and left the remaining changes to the 1.11 release note in this pull request.
comment:6 by , 8 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Created pull request documenting the removal of kwargs as well as Widget.build_attrs.
This is the first time Widget.build_attrs is documented. Does it make sense to document this in other stable branches as well? If so, would those be appropriate for this PR?