Django

Code

Ticket #11421 (new)

Opened 7 months ago

Last modified 4 months ago

Django should not silently ignore AttributeErrors raised in functions called by template

Reported by: Thomas Steinacher <tom@eggdrop.ch> Assigned to: nobody
Milestone: Component: Uncategorized
Version: SVN Keywords:
Cc: mpjung@terreon.de Triage Stage: Design decision needed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Consider atemplate

{{ obj.some_function }}

where obj's some_function exists but raises an AttributeError? because of a bug in the function's code. Django silently ignores the error and displays an empty string instead of a traceback, which could save much time when debugging.

Probably this beahaviour is because Django returns silently if we call an attribute that does not exist. But ideally it should only fail silently if the function does not exist, not if it raises an AttributeError?. Therefore Django should first check using getattr() if the function exists and THEN call it, and not catch AttributeError?.

Attachments

11421.patch (3.4 kB) - added by peterbe on 10/21/09 16:35:59.

Change History

07/04/09 15:01:51 changed by Thomas Steinacher <tom@eggdrop.ch>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Same applies for TypeError?.

08/06/09 22:11:49 changed by Alex

  • stage changed from Unreviewed to Design decision needed.

10/21/09 09:30:24 changed by anonymous

  • cc set to mpjung@terreon.de.

10/21/09 16:35:25 changed by peterbe

I created this patch based on 1.2 pre-alpha SVN-11617

Before this patch, inside _resolve_lookup(), it lump together AttributeErrors you get when doing getattr(current, bit) with AttributeErrors you get within current=current() when we in fact should treat them as two different errors. Django templates fail silently, by definition, on lookups that as in "it doesn't exist" but allows errors within propagate once found.

The patch still doesn't solve the problem with TypeErrors. Next patch maybe or a separate ticket.

10/21/09 16:35:41 changed by peterbe

  • version changed from 1.0 to SVN.

10/21/09 16:35:59 changed by peterbe

  • attachment 11421.patch added.

Add/Change #11421 (Django should not silently ignore AttributeErrors raised in functions called by template)




Change Properties
Action