#21412: Django message framework called with None
-------------------------------------+-------------------------------------
     Reporter:  merb                 |                    Owner:  Denis
                                     |  Cornehl
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.messages     |                  Version:  1.6
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  messages             |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Raffaele Salmaso):

 Hi,
 I'm using django-rest-framework Request object, and this patch make
 impossible to use it as replacement: I must use request._request, which is
 a bit ugly.

 Would it be better as

 {{{
 def add_message(request, level, message, extra_tags='',
 fail_silently=False):
     """
     Attempts to add a message to the request using the 'messages' app.
     """
     if request and hasattr(request, '_messages'):
         return request._messages.add(level, message, extra_tags)

     if not fail_silently:
         from django.conf import settings
         if 'django.contrib.messages.middleware.MessageMiddleware' not in
 settings.MIDDLEWARE:
             raise MessageFailure(
                 'You cannot add messages without installing '
                 'django.contrib.messages.middleware.MessageMiddleware'
             )
     raise TypeError("add_message() argument must be an HttpRequest like
 object, "
                     "not '%s'." % request.__class__.__name__)
 }}}

 ?

--
Ticket URL: <https://code.djangoproject.com/ticket/21412#comment:8>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.c4ef3ef1c76d40d943b9abe8c6d75d8c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to