Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
093e6c68
Kaydet (Commit)
093e6c68
authored
Kas 07, 2014
tarafından
Berker Peksag
Kaydeden (comit)
Tim Graham
Kas 27, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #14664 -- Logged a warning if MiddlewareNotUsed is raised in DEBUG mode.
üst
bd337184
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
3 deletions
+83
-3
base.py
django/core/handlers/base.py
+6
-1
1.8.txt
docs/releases/1.8.txt
+4
-0
middleware.txt
docs/topics/http/middleware.txt
+8
-1
tests.py
tests/middleware_exceptions/tests.py
+65
-1
No files found.
django/core/handlers/base.py
Dosyayı görüntüle @
093e6c68
...
@@ -49,7 +49,12 @@ class BaseHandler(object):
...
@@ -49,7 +49,12 @@ class BaseHandler(object):
mw_class
=
import_string
(
middleware_path
)
mw_class
=
import_string
(
middleware_path
)
try
:
try
:
mw_instance
=
mw_class
()
mw_instance
=
mw_class
()
except
MiddlewareNotUsed
:
except
MiddlewareNotUsed
as
exc
:
if
settings
.
DEBUG
:
if
six
.
text_type
(
exc
):
logger
.
debug
(
'MiddlewareNotUsed(
%
r):
%
s'
,
middleware_path
,
exc
)
else
:
logger
.
debug
(
'MiddlewareNotUsed:
%
r'
,
middleware_path
)
continue
continue
if
hasattr
(
mw_instance
,
'process_request'
):
if
hasattr
(
mw_instance
,
'process_request'
):
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
093e6c68
...
@@ -337,6 +337,10 @@ Middleware
...
@@ -337,6 +337,10 @@ Middleware
<django.middleware.common.CommonMiddleware.response_redirect_class>`
<django.middleware.common.CommonMiddleware.response_redirect_class>`
attribute allows you to customize the redirects issued by the middleware.
attribute allows you to customize the redirects issued by the middleware.
* A debug message will be logged to the ``django.request`` logger when a
middleware raises a :exc:`~django.core.exceptions.MiddlewareNotUsed` exception
in :setting:`DEBUG` mode.
Migrations
Migrations
^^^^^^^^^^
^^^^^^^^^^
...
...
docs/topics/http/middleware.txt
Dosyayı görüntüle @
093e6c68
...
@@ -269,7 +269,14 @@ Marking middleware as unused
...
@@ -269,7 +269,14 @@ Marking middleware as unused
It's sometimes useful to determine at run-time whether a piece of middleware
It's sometimes useful to determine at run-time whether a piece of middleware
should be used. In these cases, your middleware's ``__init__`` method may
should be used. In these cases, your middleware's ``__init__`` method may
raise :exc:`django.core.exceptions.MiddlewareNotUsed`. Django will then remove
raise :exc:`django.core.exceptions.MiddlewareNotUsed`. Django will then remove
that piece of middleware from the middleware process.
that piece of middleware from the middleware process and a debug message will
be logged to the ``django.request`` logger when :setting:`DEBUG` is set to
``True``.
.. versionchanged:: 1.8
Previously, :exc:`~django.core.exceptions.MiddlewareNotUsed` exceptions
weren't logged.
Guidelines
Guidelines
----------
----------
...
...
tests/middleware_exceptions/tests.py
Dosyayı görüntüle @
093e6c68
import
sys
import
sys
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
MiddlewareNotUsed
from
django.core.signals
import
got_request_exception
from
django.core.signals
import
got_request_exception
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.template.response
import
TemplateResponse
from
django.template.response
import
TemplateResponse
from
django.template
import
Template
from
django.template
import
Template
from
django.test
import
TestCase
,
override_settings
from
django.test
import
RequestFactory
,
TestCase
,
override_settings
from
django.test.utils
import
patch_logger
class
TestException
(
Exception
):
class
TestException
(
Exception
):
...
@@ -832,3 +834,65 @@ class RootUrlconfTests(TestCase):
...
@@ -832,3 +834,65 @@ class RootUrlconfTests(TestCase):
# the previously defined settings.
# the previously defined settings.
del
settings
.
ROOT_URLCONF
del
settings
.
ROOT_URLCONF
self
.
assertRaises
(
AttributeError
,
self
.
client
.
get
,
"/middleware_exceptions/view/"
)
self
.
assertRaises
(
AttributeError
,
self
.
client
.
get
,
"/middleware_exceptions/view/"
)
class
MyMiddleware
(
object
):
def
__init__
(
self
):
raise
MiddlewareNotUsed
def
process_request
(
self
,
request
):
pass
class
MyMiddlewareWithExceptionMessage
(
object
):
def
__init__
(
self
):
raise
MiddlewareNotUsed
(
'spam eggs'
)
def
process_request
(
self
,
request
):
pass
@override_settings
(
DEBUG
=
True
,
ROOT_URLCONF
=
'middleware_exceptions.urls'
,
)
class
MiddlewareNotUsedTests
(
TestCase
):
rf
=
RequestFactory
()
def
test_raise_exception
(
self
):
request
=
self
.
rf
.
get
(
'middleware_exceptions/view/'
)
with
self
.
assertRaises
(
MiddlewareNotUsed
):
MyMiddleware
()
.
process_request
(
request
)
@override_settings
(
MIDDLEWARE_CLASSES
=
(
'middleware_exceptions.tests.MyMiddleware'
,
))
def
test_log
(
self
):
with
patch_logger
(
'django.request'
,
'debug'
)
as
calls
:
self
.
client
.
get
(
'/middleware_exceptions/view/'
)
self
.
assertEqual
(
len
(
calls
),
1
)
self
.
assertEqual
(
calls
[
0
],
"MiddlewareNotUsed: 'middleware_exceptions.tests.MyMiddleware'"
)
@override_settings
(
MIDDLEWARE_CLASSES
=
(
'middleware_exceptions.tests.MyMiddlewareWithExceptionMessage'
,
))
def
test_log_custom_message
(
self
):
with
patch_logger
(
'django.request'
,
'debug'
)
as
calls
:
self
.
client
.
get
(
'/middleware_exceptions/view/'
)
self
.
assertEqual
(
len
(
calls
),
1
)
self
.
assertEqual
(
calls
[
0
],
"MiddlewareNotUsed('middleware_exceptions.tests.MyMiddlewareWithExceptionMessage'): spam eggs"
)
@override_settings
(
DEBUG
=
False
)
def
test_do_not_log_when_debug_is_false
(
self
):
with
patch_logger
(
'django.request'
,
'debug'
)
as
calls
:
self
.
client
.
get
(
'/middleware_exceptions/view/'
)
self
.
assertEqual
(
len
(
calls
),
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment