mirror of https://github.com/django/django.git
Fixed #35364 -- Stopped AdminEmailHandler rendering email unnecessarily.
This commit is contained in:
parent
b0f2289426
commit
50a702f3fd
|
@ -92,6 +92,13 @@ class AdminEmailHandler(logging.Handler):
|
|||
)
|
||||
|
||||
def emit(self, record):
|
||||
# Early return when no email will be sent.
|
||||
if (
|
||||
not settings.ADMINS
|
||||
# Method not overridden.
|
||||
and self.send_mail.__func__ is AdminEmailHandler.send_mail
|
||||
):
|
||||
return
|
||||
try:
|
||||
request = record.request
|
||||
subject = "%s (%s IP): %s" % (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
from contextlib import contextmanager
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
|
||||
from admin_scripts.tests import AdminScriptTestCase
|
||||
|
||||
|
@ -482,7 +483,12 @@ class AdminEmailHandlerTest(SimpleTestCase):
|
|||
None,
|
||||
None,
|
||||
)
|
||||
handler.emit(record)
|
||||
with mock.patch.object(
|
||||
handler,
|
||||
"format_subject",
|
||||
side_effect=AssertionError("Should not be called"),
|
||||
):
|
||||
handler.emit(record)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ class DefaultsTests(TestCase):
|
|||
)
|
||||
def test_custom_bad_request_template(self):
|
||||
response = self.client.get("/raises400/")
|
||||
self.assertIs(response.wsgi_request, response.context[-1].request)
|
||||
self.assertIs(response.wsgi_request, response.context.request)
|
||||
|
||||
@override_settings(
|
||||
TEMPLATES=[
|
||||
|
|
Loading…
Reference in New Issue