Opened 8 years ago

Closed 7 years ago

#4321 closed (wontfix)

BoundField.as_hidden() assumes hidden_widget is a class

Reported by: SmileyChris 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: UI/UX:

Description

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 SmileyChris 8 years ago.

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by SmileyChris

comment:1 Changed 8 years ago by adrian

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 8 years ago by adrian

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 7 years ago by lukeplant

  • Resolution set to wontfix
  • Status changed from new to closed

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