#34240 closed Bug (fixed)

assertRedirects() doesn't preserve headers set in RequestFactory/Client methods.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Testing framework Version: dev
Severity: Release blocker Keywords:
Cc: David Wobrock, Adam Johnson Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

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

  • tests/test_client_regress/tests.py

    diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
    index aaf25e2ec4..53cdc3bf07 100644
    a b class AssertRedirectsTests(SimpleTestCase):  
    613613                    status_code=302,
    614614                    target_status_code=302,
    615615                )
     616                response = req_method(
     617                    "/redirect_based_on_extra_headers_1/",
     618                    follow=False,
     619                    headers={"redirect": "val"},
     620                )
     621                self.assertRedirects(
     622                    response,
     623                    "/redirect_based_on_extra_headers_2/",
     624                    fetch_redirect_response=True,
     625                    status_code=302,
     626                    target_status_code=302,
     627                )
    616628
    617629
    618630@override_settings(ROOT_URLCONF="test_client_regress.urls")

Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.

Change History (13)

comment:1 by Carlton Gibson, 16 months ago

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

Last edited 16 months ago by Carlton Gibson (previous) (diff)

comment:2 by Carlton Gibson, 16 months ago

Triage Stage: UnreviewedAccepted

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

in reply to:  1 comment:3 by Mariusz Felisiak, 16 months ago

Replying to 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().

comment:4 by Mariusz Felisiak, 16 months ago

Description: modified (diff)

comment:5 by Carlton Gibson, 16 months ago

OK, that makes sense 😅

☕️

comment:6 by rajdesai24, 16 months ago

Owner: changed from nobody to rajdesai24
Status: newassigned

comment:7 by Adam Johnson, 16 months ago

Cc: Adam Johnson added

comment:8 by rajdesai24, 16 months ago

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

in reply to:  8 comment:9 by Mariusz Felisiak, 16 months ago

Replying to 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.

comment:10 by Mariusz Felisiak, 16 months ago

Owner: changed from rajdesai24 to Mariusz Felisiak

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

comment:11 by Mariusz Felisiak, 16 months ago

Has patch: set

comment:12 by rajdesai24, 16 months ago

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

comment:13 by GitHub <noreply@…>, 16 months ago

Resolution: fixed
Status: assignedclosed

In c2118d72:

Fixed #34240 -- Preserved headers of requests made with django.test.Client in assertRedirects().

Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.

Note: See TracTickets for help on using tickets.
Back to Top