Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 8 years ago

Summary: Widget "build_attrs" changed method signatureDocument Widget.build_attrs() signature change in Django 1.11
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:2 by brian houston morrow, 8 years ago

Owner: changed from nobody to brian houston morrow
Status: newassigned

comment:3 by brian houston morrow, 8 years ago

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?

Last edited 8 years ago by brian houston morrow (previous) (diff)

comment:4 by Melvyn Sopacua, 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 brian houston morrow, 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 Tim Graham, 8 years ago

Has patch: set
Patch needs improvement: set

comment:7 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In e86f478:

Fixed #28095 -- Doc'd Widget.build_attrs() signature change in Django 1.11.

comment:8 by Tim Graham <timograham@…>, 8 years ago

In 4bdc832:

[1.11.x] Fixed #28095 -- Doc'd Widget.build_attrs() signature change in Django 1.11.

Backport of e86f4786a7f39b0ed833c0699addf0c27811d864 from master

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