Opened 13 years ago

Closed 12 years ago

#4321 closed (wontfix)

BoundField.as_hidden() assumes hidden_widget is a class

Reported by: Chris Beaven Owned by: nobody
Component: Forms Version: master
Severity: Keywords: newforms
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The hidden_widget of a field could just as easily be (and is, in a case I'm using) a Widget instance rather than a Widget class but BoundField.as_hidden() assumes that it is always a class.

Simple patch attached checks first before trying to instantiate the hidden_widget.

Attachments (1)

hidden_widget.patch (961 bytes) - added by Chris Beaven 13 years ago.

Download all attachments as: .zip

Change History (4)

Changed 13 years ago by Chris Beaven

Attachment: hidden_widget.patch added

comment:1 Changed 13 years ago by Adrian Holovaty

What's the use case for hidden_widget being an instance rather than a class?

comment:2 Changed 13 years ago by Adrian Holovaty

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 12 years ago by Luke Plant

Resolution: wontfix
Status: newclosed

isinstance bad, duck typing good: this patch would break if hidden_widget:

  • was a class but not a subclass of Widget
  • was some other callable that returned a widget e.g. a function that wraps a Widget constructor

In fact, thinking of the latter, you can work around this perfectly if you set hidden_widget = lambda: my_widget_instance, AFAICS

So, seeing it is currently flexible enough to cope, and adding this would make it much less flexible, I'm closing WONTFIX, please reopen if I missed something.

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