Opened 3 years ago

Last modified 4 weeks ago

#16383 assigned New feature

More specific errors when resolving template Variables

Reported by: maraujop Owned by: anubhav9042
Component: Template system Version: master
Severity: Normal Keywords: _resolve_lookup, resolve, template, variable, exception
Cc: maraujop Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


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 maraujop 3 years ago.

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by maraujop

comment:1 Changed 3 years ago by maraujop

  • Cc maraujop added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by aaugustin

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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 22 months ago by CollinAnderson

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 4 weeks ago by anubhav9042

  • Owner changed from maraujop to anubhav9042
  • Status changed from new to assigned

I will work on this in my GSoC project.

comment:5 Changed 4 weeks ago by anubhav9042

  • Version changed from 1.3 to master

Add Comment

Modify Ticket

Change Properties
<Author field>
as assigned
The owner will be changed from anubhav9042 to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.