From 3399bfe98c8bd33e5738f1b66834e41874feafbc Mon Sep 17 00:00:00 2001 From: Scot Hacker Date: Sun, 24 Mar 2019 23:01:12 -0700 Subject: [PATCH] Use CharField, not TextField for MySQL compat. --- todo/mail/consumers/tracker.py | 11 ++++++++++- todo/migrations/0008_mail_tracker.py | 4 ++-- todo/models.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/todo/mail/consumers/tracker.py b/todo/mail/consumers/tracker.py index 7d5df53..001900e 100644 --- a/todo/mail/consumers/tracker.py +++ b/todo/mail/consumers/tracker.py @@ -97,7 +97,16 @@ def insert_message(task_list, message, priority, task_title_format): f"[From: {message['from']}]" ) - message_id = message["message-id"] + # Due to limitations in MySQL wrt unique_together and TextField (grrr), + # we must use a CharField rather than TextField for message_id. + # In the unlikeley event that we get a VERY long inbound + # message_id, truncate it to the max_length of a MySQL CharField. + original_message_id = message["message-id"] + message_id = ( + (original_message_id[:252] + "...") + if len(original_message_id) > 255 + else original_message_id + ) message_from = message["from"] text = message_text(message) diff --git a/todo/migrations/0008_mail_tracker.py b/todo/migrations/0008_mail_tracker.py index ea7a484..31607d0 100644 --- a/todo/migrations/0008_mail_tracker.py +++ b/todo/migrations/0008_mail_tracker.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.4 on 2018-12-21 14:01 +# Generated by Django 2.1.7 on 2019-03-24 22:50 from django.conf import settings from django.db import migrations, models @@ -18,7 +18,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name="comment", name="email_message_id", - field=models.TextField(blank=True, null=True), + field=models.CharField(blank=True, max_length=255, null=True), ), migrations.AlterField( model_name="comment", diff --git a/todo/models.py b/todo/models.py index b378b02..67e042f 100644 --- a/todo/models.py +++ b/todo/models.py @@ -130,7 +130,7 @@ class Comment(models.Model): task = models.ForeignKey(Task, on_delete=models.CASCADE) date = models.DateTimeField(default=datetime.datetime.now) email_from = models.CharField(max_length=320, blank=True, null=True) - email_message_id = models.TextField(blank=True, null=True) + email_message_id = models.CharField(max_length=255, blank=True, null=True) body = models.TextField(blank=True)