Opened 8 years ago

Closed 8 years ago

#27140 closed Bug (fixed)

Prevent template rendering from hiding a property's TypeError

Reported by: Éloi Rivard Owned by: nobody
Component: Template system Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Éloi Rivard)

If you try to access an object property in a django template, and this property raises a TypeError, then nothing will be raised. If it raises, let's say, a ZeroDivisionError, then the exception is raised.

from django.template import Context, Template
class FooClassTypeError:
    @property
    def fooproperty(self):
        raise TypeError
        return "somevalue"

class FooClass:
    @property
    def fooproperty(self):
        return 1/0

t = Template("{{ obj.fooproperty }}")

# This call does not raise anything
t.render(Context(dict(obj=FooClassTypeError())))

# This call raises an exception
t.render(Context(dict(obj=FooClass())))

I think the expected behavior is that both exceptions should be raised. What do you think?

Change History (3)

comment:1 by Éloi Rivard, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

Has patch: set
Summary: TypeError not reported from a templatePrevent template rendering from hiding a property's TypeError
Triage Stage: UnreviewedAccepted

comment:3 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 59afe61a:

Fixed #27140 -- Prevented template rendering from hiding a property's TypeError.

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