Fixed #23682 -- Enhanced circular redirects detection in tests.

When the test client detects a redirect to a URL seen in the
currently followed chain it will now raise a RedirectCycleError
instead of just returning the first repeated response.

It will also complain when a single chain of redirects is longer
than 20, as this often means a redirect loop with varying URLs,
and even if it's not actually one, such long chains are likely
to be treated as loops by browsers.

Thanks Preston Timmons, Berker Peksag, and Tim Graham for reviews.
This commit is contained in:
wrwrwr 2014-10-17 15:46:42 +02:00 committed by Tim Graham
parent a973fb2d68
commit 056a3c6c37
6 changed files with 62 additions and 10 deletions

View file

@ -217,6 +217,20 @@ Transaction exceptions are defined in :mod:`django.db.transaction`.
The :exc:`TransactionManagementError` is raised for any and all problems
related to database transactions.
.. currentmodule:: django.test
Testing Framework Exceptions
============================
Exceptions provided by the :mod:`django.test` package.
.. exception:: client.RedirectCycleError
.. versionadded:: 1.8
:exc:`~client.RedirectCycleError` is raised when the test client detects a
loop or an overly long chain of redirects.
Python Exceptions
=================