[Django] #34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client methods.

6 views
Skip to first unread message

Django

unread,
Jan 4, 2023, 3:00:19 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
---------------------------------------------+------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Similar to the #28337, HTTP headers are no longer in `extra` so they are
no longer preserved in `assertRedirects()`.

{{{#!diff
diff --git a/tests/test_client_regress/tests.py
b/tests/test_client_regress/tests.py
index aaf25e2ec4..53cdc3bf07 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -613,6 +613,18 @@ class AssertRedirectsTests(SimpleTestCase):
status_code=302,
target_status_code=302,
)
+ response = req_method(
+ "/redirect_based_on_extra_headers_1/",
+ follow=False,
+ headers={"redirect": "val"},
+ )
+ self.assertRedirects(
+ response,
+ "/redirect_based_on_extra_headers_2/",
+ fetch_redirect_response=True,
+ status_code=302,
+ target_status_code=302,
+ )


@override_settings(ROOT_URLCONF="test_client_regress.urls")
}}}

Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.

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

Django

unread,
Jan 4, 2023, 4:03:56 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+--------------------------------------

Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Carlton Gibson):

I think the regression test here isn't quite right. It fails at
b181cae2e3697b2e53b5b67ac67e59f3b05a6f0d (i.e. 67da22f0^) and
`stable/4.1.x` too. 🤔

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

Django

unread,
Jan 4, 2023, 4:07:37 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

I'll provisionally accept anyhow, assuming you're correct about the
regression.

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

Django

unread,
Jan 4, 2023, 4:11:08 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:1 Carlton Gibson]:


> I think the regression test here isn't quite right. It fails at

b181cae2e3697b2e53b5b67ac67e59f3b05a6f0d (i.e. `67da22f0^`) and
`stable/4.1.x` too. 🤔

Support for `headers` was added in
67da22f08e05018ea968fcacbac9ac37ea925d85, so it's a bug in the new
feature. Previously, `headers` went to `**extra` and was not interpreted
as HTTP headers.

After 67da22f08e05018ea968fcacbac9ac37ea925d85 `headers={"redirect":
"val"}` should work the same as `HTTP_REDIRECT="val"` and is not in
`assertRedirects()`.

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

Django

unread,
Jan 4, 2023, 4:13:03 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Description changed by Mariusz Felisiak:

Old description:

New description:

Similar to the #28337, HTTP headers can be passed in the `headers`
argument and should be preserved in `assertRedirects()`.


@override_settings(ROOT_URLCONF="test_client_regress.urls")
}}}

Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.

--

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

Django

unread,
Jan 4, 2023, 4:22:36 AM1/4/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Carlton Gibson):

OK, that makes sense 😅

☕️

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:5>

Django

unread,
Jan 5, 2023, 5:21:00 PM1/5/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+--------------------------------------
Reporter: Mariusz Felisiak | Owner: rajdesai24
Type: Bug | Status: assigned

Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by rajdesai24):

* owner: nobody => rajdesai24
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:6>

Django

unread,
Jan 7, 2023, 6:46:23 AM1/7/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+--------------------------------------
Reporter: Mariusz Felisiak | Owner: rajdesai24
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Adam Johnson):

* cc: Adam Johnson (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:7>

Django

unread,
Jan 8, 2023, 10:54:19 AM1/8/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+--------------------------------------
Reporter: Mariusz Felisiak | Owner: rajdesai24
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by rajdesai24):

hey Mariusz Felisiak can you help me with reproducing the bug. Is it just
writing test cases using assertRedirects and putting headers in the
dictionary

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:8>

Django

unread,
Jan 8, 2023, 10:57:28 AM1/8/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-----------------------------------+--------------------------------------
Reporter: Mariusz Felisiak | Owner: rajdesai24
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:8 rajdesai24]:


> hey Mariusz Felisiak can you help me with reproducing the bug. Is it
just writing test cases using assertRedirects and putting headers in the
dictionary

This is an issue in `assertRedirects()`. I've already attached a
regression test in the ticket description.

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:9>

Django

unread,
Jan 13, 2023, 4:32:39 AM1/13/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak

Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: rajdesai24 => Mariusz Felisiak


Comment:

rajdesai24 thanks for your efforts, however, I will assign it to myself as
the Django 4.2 feature freeze is on Monday (January, 16th).

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:10>

Django

unread,
Jan 13, 2023, 4:43:21 AM1/13/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16447 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:11>

Django

unread,
Jan 13, 2023, 4:55:21 AM1/13/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by rajdesai24):

Sorry, Mariuz for the delay and good I understood how you solved it.
Thanks, I will find some new bugs for myself

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:12>

Django

unread,
Jan 13, 2023, 5:31:10 AM1/13/23
to django-...@googlegroups.com
#34240: assertRedirects() doesn't preserve headers set in RequestFactory/Client
methods.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed

Component: Testing framework | Version: dev
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c2118d72d61746f2462fca695dbf3adf44ebf8f7" c2118d72]:
{{{
#!CommitTicketReference repository=""
revision="c2118d72d61746f2462fca695dbf3adf44ebf8f7"
Fixed #34240 -- Preserved headers of requests made with django.test.Client
in assertRedirects().

Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34240#comment:13>

Reply all
Reply to author
Forward
0 new messages