Opened 14 months ago

Last modified 14 months ago

#34904 closed Bug

Changing email object after sending mutates mail in mail.outbox — at Initial Version

Reported by: CheesyPhoenix Owned by: nobody
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

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)
    

I have already implemented a fix on a fork and will open a PR soon.

Change History (0)

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