Opened 12 years ago

Closed 9 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 12 years ago.

Download all attachments as: .zip

Change History (11)

Changed 12 years ago by Miguel Araujo

Attachment: _resolve_lookup.patch added

comment:1 Changed 12 years ago by Miguel Araujo

Cc: Miguel Araujo added

comment:2 Changed 12 years ago by Aymeric Augustin

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 Changed 11 years ago by Collin Anderson

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 Changed 9 years ago by ANUBHAV JOSHI

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

I will work on this in my GSoC project.

comment:5 Changed 9 years ago by ANUBHAV JOSHI

Version: 1.3master

comment:6 Changed 9 years ago by Tim Graham

Cc: Tim Graham added

comment:7 Changed 9 years ago by ANUBHAV JOSHI

Needs tests: unset

comment:8 Changed 9 years ago by Hiroki Kiyohara

Cc: hirokiky@… added

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

comment:9 Changed 9 years ago by ANUBHAV JOSHI

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

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

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