Quantcast

To keep or not to keep: logging of undefined template variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

To keep or not to keep: logging of undefined template variables

Tim Graham-2
Ticket #18773 [0] added logging of undefined template variables in Django 1.9 [1], however, I've seen several reports of users finding this logging more confusing than helpful. For example, admin templates log errors about missing is_popup variables [2] which is how the template are designed (is_popup is only in the contexts of pop ups) and the TECHNICAL_404_TEMPLATE also logs errors without any obvious solution about how to prevent that [3].

I'm thinking it might be better to remove this noisy, generally unhelpful logging. What do you think?

[0] https://code.djangoproject.com/ticket/18773
[1] https://github.com/django/django/commit/dc5b01ad05e50ccde688c73c2ed3334a956076b0
[2] https://groups.google.com/d/topic/django-users/6Ve9dcv23sI/discussion
[3] https://code.djangoproject.com/ticket/26886

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/a428f373-ef0c-4575-8a84-69a4beda154c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: To keep or not to keep: logging of undefined template variables

Tim Martin
I don't have any objection to removing this. However, the thought occurs that my patch to the handling of undefined variables could enhance this to make it more useful. I think we could log in the case where a conditional expression actually depends on an undefined variable. I haven't thought about it properly, but presumably the expression evaluation can even take account of short-circuiting, so that:

  {% if defined_value or some_undefined_value %}

correctly warns only in the case where defined_value is false. Of course, this won't help in the case of the admin template example you gave, where the conditional depends directly on the undefined value.

The obvious drawback is that I think my patch is going to be abandoned, so I think this is a purely theoretical possibility. But if anyone likes the sound of it I can think through it a little more carefully.

Tim

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/5cf29e82-19d7-4567-b537-21a77faf88a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: To keep or not to keep: logging of undefined template variables

Adam Johnson-2
Doesn't sound like there's much impetus either way, and it's confusing people, so I'd say remove it. Or maybe make it optional, default off?

On 19 March 2017 at 07:52, Tim Martin <[hidden email]> wrote:
I don't have any objection to removing this. However, the thought occurs that my patch to the handling of undefined variables could enhance this to make it more useful. I think we could log in the case where a conditional expression actually depends on an undefined variable. I haven't thought about it properly, but presumably the expression evaluation can even take account of short-circuiting, so that:

  {% if defined_value or some_undefined_value %}

correctly warns only in the case where defined_value is false. Of course, this won't help in the case of the admin template example you gave, where the conditional depends directly on the undefined value.

The obvious drawback is that I think my patch is going to be abandoned, so I think this is a purely theoretical possibility. But if anyone likes the sound of it I can think through it a little more carefully.

Tim

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/5cf29e82-19d7-4567-b537-21a77faf88a9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAMyDDM0Z-baLDh_wu59qjCxrVy%3D3xq_4xCdxP8nhZfNhL2zxew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: To keep or not to keep: logging of undefined template variables

Luke Plant-2
In reply to this post by Tim Graham-2

My general policy is that warnings should only be logged if there is a good way to silence them. A good way means:

1) fix the bug which is causing them (only applies if there is genuinely a bug or bad practice that should be fixed)

2) disable the warning in a fine tuned way i.e. you can indicate, without much work or hackiness, *this* instance generating the warning is actually fine.

Otherwise, these warnings are useless or worse - people often:

* just turn off all warnings of this type because they are too noisy (so they become useless)

* or end up turning off even more than necessary (hurting the project)

* or miss genuine issues because of the noise.

It sounds like these warnings are of the unhelpful kind.


For implementing option 2, the only thing I could think of is extending the template syntax with something that indicates you are expecting the value to be missing e.g.:

   {% if foo? %}

   {{ foo? }}

This would clearly be a big change though.


Luke


On 16/03/17 22:03, Tim Graham wrote:
Ticket #18773 [0] added logging of undefined template variables in Django 1.9 [1], however, I've seen several reports of users finding this logging more confusing than helpful. For example, admin templates log errors about missing is_popup variables [2] which is how the template are designed (is_popup is only in the contexts of pop ups) and the TECHNICAL_404_TEMPLATE also logs errors without any obvious solution about how to prevent that [3].

I'm thinking it might be better to remove this noisy, generally unhelpful logging. What do you think?

[0] https://code.djangoproject.com/ticket/18773
[1] https://github.com/django/django/commit/dc5b01ad05e50ccde688c73c2ed3334a956076b0
[2] https://groups.google.com/d/topic/django-users/6Ve9dcv23sI/discussion
[3] https://code.djangoproject.com/ticket/26886
--
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 [hidden email].
To post to this group, send email to [hidden email].
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/a428f373-ef0c-4575-8a84-69a4beda154c%40googlegroups.com.
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 [hidden email].
To post to this group, send email to [hidden email].
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/56aa2380-64a0-aa39-d9ec-5d6124f4ebde%40cantab.net.
For more options, visit https://groups.google.com/d/optout.
Loading...