Opened 7 months ago

Closed 7 months ago

#34904 closed Bug (fixed)

Changing email object after sending mutates mail in mail.outbox

Reported by: CheesyPhoenix Owned by: CheesyPhoenix
Component: Core (Mail) Version: dev
Severity: Normal Keywords: mail.outbox locmem testing
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by CheesyPhoenix)

When testing emails using the locmem email backend with mail.outbox, modifying an email object after calling .send() also modifies the email object in django.core.mail.outbox. This leads to inconsistencies between test and production environments, where an email modified in production after calling .send() will not be changed since it has already been sent.

Steps to reproduce:

  • Run this test in any django project:
    def test_mutate_after_send(self) -> None:
        email = EmailMessage(
            subject="correct subject",
            body="test body",
            from_email="from@example.com",
            to=["to@example.com"],
        )
        email.send()
        email.subject = "incorrect subject"
        self.assertEqual("correct subject", mail.outbox[0].subject)
    

GitHub PR fixing the issue: https://github.com/django/django/pull/17377

Change History (4)

comment:1 by CheesyPhoenix, 7 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 7 months ago

Owner: changed from nobody to CheesyPhoenix
Status: newassigned
Triage Stage: UnreviewedAccepted

Thanks for the report.

comment:3 by Mariusz Felisiak, 7 months ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 7 months ago

Resolution: fixed
Status: assignedclosed

In 64060d1c:

Fixed #34904 -- Prevented mutating sent emails from outbox in locmem email backend.

Note: See TracTickets for help on using tickets.
Back to Top