Skip to content

only allow redirect_chain attribute in response when client sets the follow flag #1252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

hoefling
Copy link
Contributor

Signed-off-by: Oleg Hoefling [email protected]

I have made things!

The redirect_chain attribute was added in #1124. At runtime, the response only has this attribute set when the request was made with follow=True:

In [1]: from django.test import Client

In [2]: c = Client()

In [3]: c.get('/spam', follow=True).redirect_chain
Not Found: /spam
2022-11-12 15:42:28 [WARNING ] django.request :: Not Found: /spam
Out[3]: []

In [4]: c.get('/spam', follow=False).redirect_chain
Not Found: /spam
2022-11-12 15:42:33 [WARNING ] django.request :: Not Found: /spam
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 c.get('/spam', follow=False).redirect_chain

AttributeError: 'HttpResponseNotFound' object has no attribute 'redirect_chain'

This PR replicates this behaviour.

Related issues

No issue

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like a good idea!

@hoefling hoefling requested a review from sobolevn November 12, 2022 16:55
@hoefling hoefling closed this Nov 13, 2022
hoefling added a commit to hoefling/django-stubs that referenced this pull request Nov 13, 2022
hoefling added a commit to hoefling/django-stubs that referenced this pull request Nov 13, 2022
sobolevn pushed a commit that referenced this pull request Nov 13, 2022
Signed-off-by: Oleg Hoefling <[email protected]>

Signed-off-by: Oleg Hoefling <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants