Django now reports invalid variable names by 'VariableDoesNotExist' 
exception, which is logged. So it is possible to track down invalid 
variable names. The problem I see here is inconsistency in handling invalid 
variable names. If invalid variable is rendered or used in an 'if' tag, it 
is silently turned into a string_if_invalid, if it's as a filter argument, 
it suddenly raises error.

Shai: Values are sometimes turned into an empty string in case of 
UnicodeDecodeError, see 
https://github.com/django/django/blob/master/django/template/base.py#L994-L998

IMO invalid variable should behave the same way regardless of whether it's 
printed or used as an filter argument.

Vlastik

Dne pátek 2. června 2017 8:37:35 UTC+2 Shai Berger napsal(a):
>
> I favor raising an exception in this case, because values in this context 
> are 
> not coerced to strings (unlike the case in {{ }} references). 
>
> IMO, and in order to protect the writers of all 3rd-party filters, the 
> only way 
> to solve this without raising an exception is to resolve the whole filter 
> expression to string_if_invalid, rather than just the missing var. 
>
> Shai 
>
> On Thursday 01 June 2017 03:10:39 Jon Dufresne wrote: 
> > Just my opinion, but I think raising an exception is more helpful to 
> > developers and will result in fewer unnoticed bugs. 
> > 
> > More generally, I know the template engine has a history of silently 
> > converting unknown variables to string_if_invalid but this is more 
> harmful 
> > than helpful in my experience. It continues to be a source of hard to 
> catch 
> > bugs on the projects I work on. So I'd prefer we avoid introducing more 
> of 
> > this pattern if possible. 
> > 
> > On Wed, May 31, 2017 at 8:03 AM, Tim Graham <timog...@gmail.com 
> <javascript:>> wrote: 
> > > Should nonexistent template filter arguments raise an exception? 
> Current 
> > > behavior: 
> > > 
> > > {{ value|filter:nonexistent_template_var}} 
> > > 
> > > raises VariableDoesNotExist for nonexistent_template_var. 
> > > 
> > > I guess the proposal would be to make nonexistent_tempatle_var resolve 
> to 
> > > string_if_invalid. As for me, I think the current behavior is less 
> error 
> > > prone. 
> > > 
> > > Related tickets: 
> > > 
> > > https://code.djangoproject.com/ticket/13167 
> > > This was first closed incorrectly as "fixed" by Jacob (actually a 
> > > different issue was fixed), then amended as wontfix by Karen with the 
> > > note, "I'm fine with wontfixing that, though it does rather seem to go 
> > > against "template errors don't raise exceptions" philosophy." 
> > > 
> > > https://code.djangoproject.com/ticket/28172 
> > > A follow up ticket requesting the same thing as #13167. 
> > > 
> > > -- 
> > > You received this message because you are subscribed to the Google 
> Groups 
> > > "Django developers (Contributions to Django itself)" group. 
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > > email to django-develop...@googlegroups.com <javascript:>. 
> > > To post to this group, send email to django-d...@googlegroups.com 
> <javascript:>. 
> > > Visit this group at https://groups.google.com/group/django-developers. 
>
> > > To view this discussion on the web visit https://groups.google.com/d/ 
> > > msgid/django-developers/02727bd0-5a67-4cf9-9c3f- 
> > > b0a0a7ea0a3a%40googlegroups.com 
> > > <
> https://groups.google.com/d/msgid/django-developers/02727bd0-5a67-4cf9-9 
> > > c3f-b0a0a7ea0a3a%40googlegroups.com?utm_medium=email&utm_source=footer> 
> . 
> > > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/163523b9-00f5-4327-9803-6eca49f668da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to