[Django] #25763: Django missing repr friendly formatting of request

13 views
Skip to first unread message

Django

unread,
Nov 16, 2015, 9:34:33 AM11/16/15
to django-...@googlegroups.com
#25763: Django missing repr friendly formatting of request
------------------------------+--------------------
Reporter: atarkowska | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------
I found this feature https://docs.djangoproject.com/en/1.6/topics/logging
/#django-request-logger very useful. Since upgrade to 1.8 request object
is no longer nicely formatted


formatter:
{{{
'%(asctime)s %(levelname)5.5s [%(name)40.40s]'
' (proc.%(process)5.5d) %(funcName)s():%(lineno)d'
' HTTP %(status_code)d REQUEST %(request)s')
}}}

{{{
2015-11-16 13:45:55,579 ERROR [ django.request]
(proc.07627) handle_uncaught_exception():256 HTTP 500 REQUEST
<WSGIRequest: GET '/app/error_page/'>
Traceback (most recent call last):...
}}}

str or repr(request) is missing, GET, POST, COOKIES and META

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

Django

unread,
Nov 16, 2015, 10:19:13 AM11/16/15
to django-...@googlegroups.com
#25763: Django missing repr friendly formatting of request
------------------------------+--------------------------------------

Reporter: atarkowska | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

This is an intentional change in #12098 and documented in the 1.8 release
notes.

Any ideas about how we can improve the situation are welcome, but I don't
think we're going to revert that patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/25763#comment:1>

Django

unread,
Nov 16, 2015, 11:32:00 AM11/16/15
to django-...@googlegroups.com
#25763: Django missing repr friendly formatting of request
------------------------------+--------------------------------------

Reporter: atarkowska | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by atarkowska):

Tim is it not what logging formatting is for?

class HttpRequest(object):
{{{
def __repr__(self):
return build_request_repr(self)

def __str__(self):
if self.method is None or not self.get_full_path():
return force_str('<%s>' % self.__class__.__name__)
return force_str(
'<%s: %s %r>' % (self.__class__.__name__, self.method,
force_str(self.get_full_path()))
)
}}}


logging formatter
{{{
' HTTP %(status_code)d %(request)r'
}}}

{{{
<WSGIRequest: GET '/webapp/error_page/'>
[16/Nov/2015 16:29:46] "GET /webapp/error_page/ HTTP/1.1" 200 8366
}}}

works for me

I will create a patch for that

--
Ticket URL: <https://code.djangoproject.com/ticket/25763#comment:2>

Django

unread,
Nov 16, 2015, 11:52:28 AM11/16/15
to django-...@googlegroups.com
#25763: Django missing repr friendly formatting of request
------------------------------+--------------------------------------

Reporter: atarkowska | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by timgraham):

`build_request_repr()` was removed in #25099. It solved some security
headaches like #22990. I think we want to promote ways of request logging
that avoid things like raw passwords in logs.

--
Ticket URL: <https://code.djangoproject.com/ticket/25763#comment:3>

Django

unread,
Nov 17, 2015, 11:09:00 AM11/17/15
to django-...@googlegroups.com
#25763: Django missing repr friendly formatting of request
------------------------------+--------------------------------------
Reporter: atarkowska | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.8
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => wontfix


Comment:

I think you should be able to write a custom logging handler similar to
`AdminEmailHandler` which uses `record.request` to format the request data
any way you like. This might be something we'd consider for inclusion in
Django itself, although since no one has complained until seven months
after the release of Django 1.8, I guess it's not a popular use case. Feel
free to raise the issue on the DevelopersMailingList if you feel my
analysis is off-base. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/25763#comment:4>

Reply all
Reply to author
Forward
0 new messages