#27233: IndexError when using django.request
-------------------------+-------------------------------------------------
     Reporter:  ben-     |      Owner:  nobody
  whale                  |
         Type:  Bug      |     Status:  new
    Component:           |    Version:  1.10
  Uncategorized          |
     Severity:  Normal   |   Keywords:  django.request runserver IndexError
 Triage Stage:           |  Has patch:  0
  Unreviewed             |
Easy pickings:  0        |      UI/UX:  0
-------------------------+-------------------------------------------------
 To replicate the following stacktrace:

 {{{
 Traceback (most recent call last):
   File "/usr/lib/python2.7/logging/__init__.py", line 861, in emit
     msg = self.format(record)
   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
     return fmt.format(record)
   File "<path_to_project>/mwe/venv/local/lib/python2.7/site-
 packages/django/utils/log.py", line 173, in format
     if args[1][0] == '2':
 IndexError: tuple index out of range
 }}}



 follow these steps:
 1) create a project "django-admin startproject <project_name>"
 2) put the following into settings.py
 {{{
 LOGGING = {
     'version': 1,
     'disable_existing_loggers': False,
     'formatters': {
         'custom': {
             '()': 'django.utils.log.ServerFormatter',
             'format': '[%(server_time)s] %(message)s %(request)r',
         }
     },
     'handlers': {
         'custom': {
             'level': 'INFO',
             'class': 'logging.StreamHandler',
             'formatter': 'custom',
         },
     },
     'loggers': {
         'django.request': {
             'handlers': ['custom'],
             'level': 'DEBUG',
             'propagate': False,
         },
     }
 }
 }}}
 3) run the server "python manage.py runserver"
 4) navigate to <server>/foobar

 The traceback should be printed in the console.

 TBH I was sure what to expect as the documentation
 (https://docs.djangoproject.com/en/1.10/topics/logging/#django-request)
 doesn't make it clear if the django.request logger is used when using the
 runserver command, especially when django.server essentially replicates
 django.request when running using runserver.

 The error occurs (I think) as the format method expects args to be a tuple
 consisting of the url, the response status code, and a number (the amount
 of data transferred?) but instead receives a tuple containing only the
 url.

--
Ticket URL: <https://code.djangoproject.com/ticket/27233>
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/052.e1a8e162ba349c6c94a0eedbb9cf5b49%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to