Opened 5 years ago

Closed 5 years ago

#24713 closed Bug (wontfix)

Redirect loop detection in test client is incorrect

Reported by: agmathew Owned by:
Component: Testing framework Version: 1.8
Severity: Release blocker Keywords: redirect loop detection test client
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

We recently upgraded our Django installation from 1.6 and 1.8 and noticed our unit tests were failing in multiple places. We tracked down the problem to changes stemming from the fix for #23682, which introduces stronger looper detection for redirects. The problem is that we have logic in our codebase that goes like this:

  • Go to /view/
  • If a dirty bit is set, redirect to /update/ and remove the dirty bit
  • Redirect back to /view/

The loop detection erroneously considers this a redirect loop because /view/ is visited twice. Browsers don't have a problem with our redirects. I propose that the redirect loop detection should check that a previous site has been visited N times (for some value of N) before reporting a redirect loop. If this sounds reasonable, I can create a patch.

Change History (7)

comment:1 Changed 5 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Yes, it does seem reasonable.

comment:2 Changed 5 years ago by Mounir

Owner: changed from nobody to Mounir
Status: newassigned

comment:3 Changed 5 years ago by Mounir

Please review my PullRequest and check if we raise the RedirectCycleError when redirecting to the same page more than 2 time is okay or we need to make it greater.

comment:4 Changed 5 years ago by Mounir

Owner: Mounir deleted
Status: assignednew

comment:5 Changed 5 years ago by Tim Graham

Has patch: set
Needs tests: set

comment:6 Changed 5 years ago by Tim Graham

From Mounir on the pull request:

I don't think making multiple redirects for a client is the right way. Let take an example: A user is trying to access a home page "/home" and the server need to update an information, let's say a last_visit datetime field or something else -- do we need to redirect him to "/update" make this update and redirect him again to "/home"? I think it's better to run a signal, an asynchronous task, make the update by calling a model method or something else or even do the logic from the "/home" view. If we are not sure that this is a common issue for many (now it look like only one person have this problem) I think it's better to keep things like they are.

I'd agree with this. Is there a reason you can't restructure your code to avoid the redirect? See also the discussion on the django-developers mailing list.

comment:7 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top