Opened 8 years ago
Closed 8 years ago
#27233 closed Bug (invalid)
IndexError when using django.request
Reported by: | Ben Whale | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.10 |
Severity: | Normal | Keywords: | django.request runserver IndexError |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (3)
follow-up: 2 comment:1 by , 8 years ago
comment:2 by , 8 years ago
Replying to timgraham:
Unless you say where the bug is, it looks invalid to me to use 'django.utils.log.ServerFormatter' attached to a logger other than 'django.server`'.
Haha ha ha. Yes. Yes it is. Some debugging latter and I can see that you are quite right.
comment:3 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Unless you say where the bug is, it looks invalid to me to use 'django.utils.log.ServerFormatter' attached to a logger other than 'django.server`'.