Opened 17 years ago

Closed 13 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: dev
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@…> 17 years ago.
7153.diff (3.3 KB ) - added by Alexander Koshelev 16 years ago.
Better path with tests for current trunk
7153.2.diff (6.9 KB ) - added by Chris Beaven 15 years ago.
another test, and also adding catching silent variable failures everywhere (with tests)
7153.3.diff (14.3 KB ) - added by Chris Beaven 14 years ago.

Download all attachments as: .zip

Change History (17)

by Ionut Ciocirlan <ionut.ciocirlan@…>, 17 years ago

Attachment: template_callable.diff added

comment:1 by Simon Greenhill, 16 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by Russell Keith-Magee, 16 years ago

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 by anonymous, 16 years ago

Cc: daevaorn@… added

by Alexander Koshelev, 16 years ago

Attachment: 7153.diff added

Better path with tests for current trunk

comment:4 by Alexander Koshelev, 16 years ago

Needs tests: unset

by Chris Beaven, 15 years ago

Attachment: 7153.2.diff added

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

comment:5 by Chris Beaven, 15 years ago

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 by Matthias Kestenholz, 14 years ago

Patch does not apply anymore.

comment:7 by Chris Beaven, 14 years ago

Patch needs improvement: set

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

by Chris Beaven, 14 years ago

Attachment: 7153.3.diff added

comment:8 by Chris Beaven, 14 years ago

Patch needs improvement: unset

comment:9 by Chris Beaven, 14 years ago

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 by Tai Lee, 14 years ago

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

comment:11 by Luke Plant, 14 years ago

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

Thanks to Tai Lee for the patch.

Refs #15025, #7153

comment:12 by charlie leifer, 13 years ago

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 by anonymous, 13 years ago

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