Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#31605 closed Bug (needsinfo)

messages shortcuts will not process with whitespace.

Reported by: Rory Patrick Sheridan Owned by: nobody
Component: contrib.messages Version: 3.0
Severity: Normal Keywords: messages, shortcuts, cookies, success, error, bug, message
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Rory Patrick Sheridan)

When using:

messages.success(request, 'str')

or other shortcuts, messages that contain any whitespace do not show. A message that is a single string of characters with no whitespace such as "thisisanexample" will display, however "this is an example" or even " " will not be displayed on the page.

The cookie data is processed by the backend, as it can be seen in the cookies, but it is never read when parsing the page templates.
{% if messages %} returns False, so it isn't being read at all.

The exact same code but with no whitespace results in functionality.
I have tested it on Chrome and Chrome Android and it is the same on both devices, same version, Stable Chrome builds.
I have tested it using tutorial code as well.
I have reproduced it using django 2.2.12.
I haven't tested other methods of displaying messages outside of shortcuts.

my relevant code:

def post_add(request):

    next = request.GET.get('next', '')
    if request.method == 'POST':
        form = PostForm(request.POST)

        if form.is_valid():
            form.save()
            messages.success(request, 'This is an example')
            return HttpResponseRedirect(next)

    else:
        form = PostForm()
    return HttpResponseRedirect(next)

Cookie data examples here:

"44cb14ea2f1cade16b5dad1524386ff0ef096317$[[\"__json_message\"\0540\05440\054\"This is an example\"]]"
"2c19fe90a788435e86265a97348ae12eac4780d8$[[\"__json_message\"\0540\05425\054\"This is an example\"]]"

Attachments (3)

Screenshot 2020-05-19 at 02.59.53.2.png (4.4 KB ) - added by Rory Patrick Sheridan 5 years ago.
Shows that the message fires if there is no whitespace in the string
Screenshot 2020-05-19 at 02.37.55.png (46.6 KB ) - added by Rory Patrick Sheridan 5 years ago.
Cookie has been populated
Screenshot 2020-05-19 at 02.59.53.png (4.4 KB ) - added by Rory Patrick Sheridan 5 years ago.
Shows that message fire without whitespace only

Download all attachments as: .zip

Change History (9)

by Rory Patrick Sheridan, 5 years ago

Shows that the message fires if there is no whitespace in the string

comment:1 by Rory Patrick Sheridan, 5 years ago

Description: modified (diff)

comment:2 by Rory Patrick Sheridan, 5 years ago

Description: modified (diff)

comment:3 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed
Summary: messages shortcuts will not process with whitespacemessages shortcuts will not process with whitespace.

messages works for me, you probably missed adding django.contrib.messages.context_processors.messages to the context_processors option of the DjangoTemplates backend defined in your TEMPLATES setting. Please use one of support channels if you have further questions.

Closing per TicketClosingReasons/UseSupportChannels.

comment:4 by Rory Patrick Sheridan, 5 years ago

Resolution: invalid
Status: closednew

That is in context processors, it is added by default.

Also, take not of the screenshots. Messages works just fine when there is no whitespace with the exact same code. Why would that happen if that was missing from context processors?

Did you even read what was written or looked at the attached files? I have screenshots showing that when there is whitespace it shows in cookies, but is not parsed by the page as messages, contrasted with no whitespace and messages showing up. The code is fully functional for messages when they lack whitespace.
I have also tested using tutorials and code examples from the django website, as well as other versions of django (as I have already stated).

Version 3, edited 5 years ago by Rory Patrick Sheridan (previous) (next) (diff)

by Rory Patrick Sheridan, 5 years ago

Cookie has been populated

by Rory Patrick Sheridan, 5 years ago

Shows that message fire without whitespace only

in reply to:  4 ; comment:5 by Mariusz Felisiak, 5 years ago

Resolution: needsinfo
Status: newclosed

Did you even read what was written or looked at the attached files?

Yes. Please be kinder.

I have screenshots showing that when there is whitespace it shows in cookies, but is not parsed by the page as messages, contrasted with no whitespace and messages showing up. The code is fully functional for messages when they lack whitespace.

Screenshots do not prove that there is an issue in Django. As I said, messages works properly for me, with and without whitespaces. Please don't reopen this ticket without providing a small sample project to reproduce your issue.

in reply to:  5 comment:6 by Rory Patrick Sheridan, 5 years ago

Replying to felixxm:

Yes. Please be kinder.

Fair enough, I can be kinder, but please be more thorough and clear. Your initial response was fairly flippant and frankly bad practice for dealing with bugs.
Suggesting I'm missing something that is required to display messages (and run a project with the admin panel, no less) when I have provided a screenshot of messages being displayed isn't exactly going to convince me that you paid any attention at all.

Screenshots do not prove that there is an issue in Django. As I said, messages works properly for me, with and without whitespaces. Please don't reopen this ticket without providing a small sample project to reproduce your issue.

No, it doesn't prove there's an issue, but it certainly does prove more than "Oh it's implemented incorrectly". Everything "works for me" until it encounters a circumstance in which it doesn't and then should be examined. "Needsinfo" is more appropriate.

However, I'm not really in a position to share the project. I'll see if I can get some other sample in the meantime.

Note: See TracTickets for help on using tickets.
Back to Top