Skip to content

Update Python and Django supported versions#308

Open
pfouque wants to merge 2 commits intomasterfrom
django6
Open

Update Python and Django supported versions#308
pfouque wants to merge 2 commits intomasterfrom
django6

Conversation

@pfouque
Copy link
Collaborator

@pfouque pfouque commented Jan 27, 2026

Update CI to current django versions

  • Add Python 3.13, 3.14 support
  • Add Django 5.1, 5.2, 6.0 support
  • Remove support for deprecated Django versions

Fix reply message parsing in Django 6 by avoiding legacy round‑trip

Root cause
Django 6 switched EmailMessage.message() to return Python’s modern email.message.EmailMessage. We were serializing that object to a string and re‑parsing it with email.message_from_string(), which produces a legacy compat32 Message. That round‑trip dropped/failed to expose the In-Reply-To header, so _process_message never set in_reply_to, causing test_message_reply to fail.

Fix
Skip the serialize/parse round‑trip and pass the EmailMessage object directly into record_outgoing_message. This preserves the In-Reply-To header and makes reply handling work consistently on Django 6+.

NB: I dunno why this round‑trip was implemented in a first place, but all tests are passing now...

@pfouque pfouque force-pushed the django6 branch 4 times, most recently from 94171e2 to 4d2f02e Compare January 27, 2026 12:06
@pfouque pfouque marked this pull request as ready for review January 28, 2026 04:35
@pfouque pfouque changed the title Update CI to test new django versions Update Python and Django supported versions Jan 28, 2026
Comment on lines -678 to -680
email.message_from_string(
message.message().as_string()
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misunderstanding what you wrote in your PR description, but won't this only work for Django 6+, while I believe you've left the repo set to continue supporting 5?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @coddingtonbear,
the main change in Django 6.0 is that message.message() now returns a <class 'email.message.EmailMessage'> instead of <class 'django.core.mail.message.SafeMIMEText'>.
But the new class, when serialized-deserialized as string, does not preserve custom headers like In-Reply-To.

I started with a Django 6 only fix, but it appeared that the serialization-deserialization wasn't useful (according to the test suite)
But I can definitely add a statement to apply it only for Django6+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants