Opened 4 years ago

Closed 13 months ago

#16383 closed New feature (fixed)

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, timo, 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 maraujop 4 years ago.

Download all attachments as: .zip

Change History (11)

Changed 4 years ago by maraujop

comment:1 Changed 4 years ago by maraujop

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

comment:2 Changed 4 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 3 years 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 15 months 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 15 months ago by anubhav9042

  • Version changed from 1.3 to master

comment:6 Changed 14 months ago by timo

  • Cc timo added

comment:7 Changed 13 months ago by anubhav9042

  • Needs tests unset

comment:8 Changed 13 months ago by hirokiky

  • 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 13 months ago by anubhav9042

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

comment:10 Changed 13 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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