#33458: Messages framework incorrectly serializes/deserializes extra_tags when 
it's
an empty string
--------------------------------------------+------------------------
               Reporter:  Tim McCurrach     |          Owner:  nobody
                   Type:  Bug               |         Status:  new
              Component:  contrib.messages  |        Version:  4.0
               Severity:  Normal            |       Keywords:
           Triage Stage:  Unreviewed        |      Has patch:  0
    Needs documentation:  0                 |    Needs tests:  0
Patch needs improvement:  0                 |  Easy pickings:  0
                  UI/UX:  0                 |
--------------------------------------------+------------------------
 When a message is serialised and then deserialised with any of the built
 in storage backends, then `extra_tags==""` is converted to
 `extra_tags==None`. This is because `MessageEncoder` checks for the
 truthyness of `extra_tags` rather than checking it is not `None`.

 === To replicate this bug ===

 {{{
 >>> from django.conf import settings
 >>> settings.configure()  # Just to allow the following import
 >>> from django.contrib.messages.storage.base import Message
 >>> from django.contrib.messages.storage.cookie import MessageEncoder,
 MessageDecoder
 >>> original_message = Message(10, "Here is a message", extra_tags="")
 >>> encoded_message = MessageEncoder().encode(original_message)
 >>> decoded_message = MessageDecoder().decode(encoded_message)
 >>> original_message.extra_tags == ""
 True
 >>> decoded_message.extra_tags is None
 True
 }}}

 === Effect of the bug in application behaviour ===
 This error occurred in the wild with a template tag similar to the
 following:
 {{{
 {% if x not in message.extra_tags %}
 }}}
 When the message was displayed as part of a redirect, it had been
 serialised and deserialized which meant that extra_tags was `None` instead
 of the empty string. This caused an error.

 It's important to note that this bug affects all of the standard API
 (`messages.debug`, `messages.info` etc. all have a default value of
 `extra_tags` equal to `""`).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33458>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.df37a3df3639ff8e90e314ef0266585c%40djangoproject.com.

Reply via email to