Opened 7 years ago

Closed 4 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: SmileyChris
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@…> 7 years ago.
7153.diff (3.3 KB) - added by alexkoshelev 7 years ago.
Better path with tests for current trunk
7153.2.diff (6.9 KB) - added by SmileyChris 6 years ago.
another test, and also adding catching silent variable failures everywhere (with tests)
7153.3.diff (14.3 KB) - added by SmileyChris 5 years ago.

Download all attachments as: .zip

Change History (17)

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

comment:1 Changed 7 years ago by Simon Greenhill

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 7 years ago by russellm

  • Needs tests set
  • Triage Stage changed from Ready for checkin to Accepted

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

  • Cc daevaorn@… added

Changed 7 years ago by alexkoshelev

Better path with tests for current trunk

comment:4 Changed 7 years ago by alexkoshelev

  • Needs tests unset

Changed 6 years ago by SmileyChris

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

comment:5 Changed 6 years ago by SmileyChris

  • Owner changed from nobody to SmileyChris
  • Status changed from new to assigned
  • Summary changed from Not all callables are run by the template system to _resolve_lookup could do a better job of resolving callables and correctly catching silent_variable_failure exceptions

comment:6 Changed 5 years ago by mk

Patch does not apply anymore.

comment:7 Changed 5 years ago by SmileyChris

  • Patch needs improvement set

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

Changed 5 years ago by SmileyChris

comment:8 Changed 5 years ago by SmileyChris

  • Patch needs improvement unset

comment:9 Changed 5 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:10 Changed 5 years ago by mrmachine

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

comment:11 Changed 5 years ago by lukeplant

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

Thanks to Tai Lee for the patch.

Refs #15025, #7153

comment:12 Changed 4 years ago by charlie leifer

  • Easy pickings unset
  • Resolution fixed deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to 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 4 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

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