Opened 14 months ago
Last modified 14 months ago
#34904 closed Bug
Changing email object after sending mutates mail in mail.outbox — at Version 1
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 (last modified by )
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
Note:
See TracTickets
for help on using tickets.