Opened 8 years ago

Closed 5 years ago

#7153 closed Bug (fixed)

_resolve_lookup could do a better job of resolving callables and correctly catching silent_variable_failure exceptions

Reported by: Ionut Ciocirlan <ionut.ciocirlan@…> Owned by: Chris Beaven
Component: Template system Version: master
Severity: Normal Keywords: template callable
Cc: daevaorn@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Right now callables are run only if they are object methods and dictionary lookup failed (which means a DictMixin-like method wouldn't get called).

I don't think this is meant by design, so this patch moves the callable check at the end of _resolve_lookup(), making all callables passed to the template get run.

Attachments (4)

template_callable.diff (2.5 KB) - added by Ionut Ciocirlan <ionut.ciocirlan@…> 8 years ago.
7153.diff (3.3 KB) - added by Alexander Koshelev 8 years ago.
Better path with tests for current trunk
7153.2.diff (6.9 KB) - added by Chris Beaven 7 years ago.
another test, and also adding catching silent variable failures everywhere (with tests)
7153.3.diff (14.3 KB) - added by Chris Beaven 6 years ago.

Download all attachments as: .zip

Change History (17)

Changed 8 years ago by Ionut Ciocirlan <ionut.ciocirlan@…>

Attachment: template_callable.diff added

comment:1 Changed 8 years ago by Simon Greenhill

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedReady for checkin

comment:2 Changed 8 years ago by Russell Keith-Magee

Needs tests: set
Triage Stage: Ready for checkinAccepted

Sounds like a reasonable proposition, but I'm not going to check in something like this without tests. Reminder to triagers - tests are not optional.

comment:3 Changed 8 years ago by anonymous

Cc: daevaorn@… added

Changed 8 years ago by Alexander Koshelev

Attachment: 7153.diff added

Better path with tests for current trunk

comment:4 Changed 8 years ago by Alexander Koshelev

Needs tests: unset

Changed 7 years ago by Chris Beaven

Attachment: 7153.2.diff added

another test, and also adding catching silent variable failures everywhere (with tests)

comment:5 Changed 7 years ago by Chris Beaven

Owner: changed from nobody to Chris Beaven
Status: newassigned
Summary: Not all callables are run by the template system_resolve_lookup could do a better job of resolving callables and correctly catching silent_variable_failure exceptions

comment:6 Changed 6 years ago by Matthias Kestenholz

Patch does not apply anymore.

comment:7 Changed 6 years ago by Chris Beaven

Patch needs improvement: set

PS: you're doing a great job of triage, mk.

Changed 6 years ago by Chris Beaven

Attachment: 7153.3.diff added

comment:8 Changed 6 years ago by Chris Beaven

Patch needs improvement: unset

comment:9 Changed 6 years ago by Chris Beaven

Resolution: fixed
Status: assignedclosed

(In [14992]) Fixed #7153 -- _resolve_lookup now does a better job of resolving callables and correctly catches all silent_variable_exceptions

comment:10 Changed 6 years ago by Tai Lee

See #15057 for a patch with improved docs that describe the new behaviour.

comment:11 Changed 6 years ago by Luke Plant

(In [15188]) Fixed #15057 - documented change in [14992]

Thanks to Tai Lee for the patch.

Refs #15025, #7153

comment:12 Changed 5 years ago by charlie leifer

Easy pickings: unset
Resolution: fixed
Severity: Normal
Status: closedreopened
Type: Bug
UI/UX: unset

This causes issues in any variable where the context lookup is a class. Rather than the class being returned, a bare instance is (assuming it can be instantiated without parameters). Is this expected behavior?

Here's how I ran into the issue: I drop a couple models into the context and do things with them in the template, namely passing the models in as filter arguments. In django 1.2.X, the classes are passed along intact into the filter. In 1.3.X, a bare instance of the class is passed in to the filter instead.

comment:13 Changed 5 years ago by anonymous

Resolution: fixed
Status: reopenedclosed

Near as I can tell the behavior you note is expected and documented as a 1.3 change: https://docs.djangoproject.com/en/1.3/releases/1.3/#callables-in-templates

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