[Django] #12607: django.test.client.Client changes the HTTP method to "GET" when doing a redirect.

0 views
Skip to first unread message

Django

unread,
Jan 14, 2010, 1:10:05 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12607: django.test.client.Client changes the HTTP method to "GET" when doing a
redirect.
-------------------------------------------+--------------------------------
Reporter: pbiggar | Owner: nobody
Status: new | Milestone: 1.2
Component: Testing framework | Version: 1.2-alpha
Keywords: get redirect _handle_redirect | Stage: Unreviewed
Has_patch: 0 |
-------------------------------------------+--------------------------------
With the code:

Client().post(path, {}, follow=True)

where path causes a redirect, the HTTP verb will be changed to a GET. This
is probably due to line 949 of
http://code.djangoproject.com/svn/django/trunk/django/test/client.py.
_handle_redirect is called from post(), put(), delete() etc, even though
it redirects by calling get().

(My knowledge of HTTP is hazy, but it seems wrong to change this.)

Workaround: make sure tests dont redirect (which probably means avoid the
automatic redirection of leaving a '/' off the end of paths).

I'm experiencing this with Django 1.1, but it looks like its still present
in svn.

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

Django

unread,
Jan 14, 2010, 1:13:38 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12607: django.test.client.Client changes the HTTP method to "GET" when doing a
redirect.
----------------------------------------+-----------------------------------
Reporter: pbiggar | Owner: nobody
Status: closed | Milestone: 1.2
Component: Testing framework | Version: 1.2-alpha
Resolution: invalid | Keywords: get redirect _handle_redirect
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------+-----------------------------------
Changes (by russellm):

* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0

Comment:

This is the intended behavior - the test client is doing exactly what a
browser does. If you POST to a URL, and the POST returns a redirect, the
browser doesn't POST the request to the redirected URL - it *always* uses
GET for the redirected URL.

--
Ticket URL: <http://code.djangoproject.com/ticket/12607#comment:1>

Django

unread,
Jan 14, 2010, 1:17:51 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12607: django.test.client.Client changes the HTTP method to "GET" when doing a
redirect.
----------------------------------------+-----------------------------------
Reporter: pbiggar | Owner: nobody
Status: closed | Milestone: 1.2
Component: Testing framework | Version: 1.2-alpha
Resolution: invalid | Keywords: get redirect _handle_redirect
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------+-----------------------------------
Comment (by Alex):

I just read through RFC2616 and you are correct that the spec says that
you are supposed to redirect using the same request method, however the
spec specifically notes that most clients transform any redirects into a
GET, this is the behavior of most web browsers, AFAIK. I think the
solution here might be for you to just use follow=False and do the
redirect tracking manually, as I think the django test client wants to
stay similar to browsers.

--
Ticket URL: <http://code.djangoproject.com/ticket/12607#comment:2>
Reply all
Reply to author
Forward
0 new messages