Opened 13 years ago

Closed 10 years ago

#16383 closed New feature (fixed)

More specific errors when resolving template Variables

Reported by: Miguel Araujo Owned by: ANUBHAV JOSHI
Component: Template system Version: dev
Severity: Normal Keywords: _resolve_lookup, resolve, template, variable, exception
Cc: Miguel Araujo, Tim Graham, hirokiky@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When resolving a template variable that calls an object method/property. If that method/property has errors we get a VariableDoesNotExist exception without what errors happened, which might confuse the user.

My patch raises the same exception, with related error information. I wasn't sure what type of Exception raise and probably the exception message is not the best one.


Attachments (1)

_resolve_lookup.patch (954 bytes ) - added by Miguel Araujo 13 years ago.

Download all attachments as: .zip

Change History (11)

by Miguel Araujo, 13 years ago

Attachment: _resolve_lookup.patch added

comment:1 by Miguel Araujo, 13 years ago

Cc: Miguel Araujo added

comment:2 by Aymeric Augustin, 13 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

Overall, I like the idea of raising more specific errors.

See also #6907 and #11421.

It would be useful to discuss the details on django-developers.

comment:3 by Collin Anderson, 12 years ago

I ran into this one today. The patch would fix it for me. I was trying to do {{ form.errors }} (errors is a @property), and my validation code caused an AttributeError. I didn't need to call form.is_valid() in the view.

So, actually, if we know for sure that the object in the context (current) does indeed have that attribute (bit), then we should really just re-raise the original exception.

comment:4 by ANUBHAV JOSHI, 10 years ago

Owner: changed from Miguel Araujo to ANUBHAV JOSHI
Status: newassigned

I will work on this in my GSoC project.

comment:5 by ANUBHAV JOSHI, 10 years ago

Version: 1.3master

comment:6 by Tim Graham, 10 years ago

Cc: Tim Graham added

comment:8 by Hiroki Kiyohara, 10 years ago

Cc: hirokiky@… added

this pull-request is focus when some property raise AttributeError, right?
I just commented about problem on the surface.

comment:9 by ANUBHAV JOSHI, 10 years ago

Yep.
If a property raises AttributeError, so it occured as if property didn't existed...so I checked that.

comment:10 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 0dd05c9e66ebb5cb97136f84373f43582783e1a6:

Fixed #16383 -- Raised the AttributeError raised in property of an object when used in a template.

Thanks maraujop for the report and Hiroki and Tim Graham for review.

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