#34904: Changing email object after sending mutates mail in mail.outbox -------------------------------------+------------------------------------- Reporter: | Owner: nobody CheesyPhoenix | Type: Bug | Status: new Component: Core | Version: dev (Mail) | Keywords: mail.outbox locmem Severity: Normal | testing Triage Stage: | Has patch: 1 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- 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: {{{#!python def test_mutate_after_send(self) -> None: email = EmailMessage( subject="correct subject", body="test body", from_email="f...@example.com", to=["t...@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. -- Ticket URL: <https://code.djangoproject.com/ticket/34904> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018b4335e8b5-bd082523-ac94-4035-a853-bee7be147f32-000000%40eu-central-1.amazonses.com.