Repository: python-discord/site

Issue:
Message Model is limited to 2k characters
https://github.com/python-discord/site/blob/297337fa6552ec32d95e82dc41c018ef1a5e3cf3/pydis_site/apps/api/models/bot/message.py#L46

Nitro now provides the ability to submit messages 4k characters long. When antispam in the bot attempts deletion of messages this size, it uploads them to bot/deleted_messages, which then fails with 400 Bad Request because an individual message doesn't validate. 

I've marked this as high because we actually lose the content of the deleted messages here due to the failed POST from the bot.


Discussion:
I'll make a PR for this shortly


Resolving patch:
diff --git a/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py b/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py
new file mode 100644
--- /dev/null
+++ b/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.14 on 2021-06-24 14:45
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0070_auto_20210618_2114'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='deletedmessage',
+            name='content',
+            field=models.CharField(blank=True, help_text='The content of this message, taken from Discord.', max_length=4000),
+        ),
+    ]
diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py
--- a/pydis_site/apps/api/models/bot/message.py
+++ b/pydis_site/apps/api/models/bot/message.py
@@ -43,7 +43,7 @@ class Message(ModelReprMixin, models.Model):
         verbose_name="Channel ID"
     )
     content = models.CharField(
-        max_length=2_000,
+        max_length=4_000,
         help_text="The content of this message, taken from Discord.",
         blank=True
     )


Test patch:
diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py
--- a/pydis_site/apps/api/tests/test_models.py
+++ b/pydis_site/apps/api/tests/test_models.py
@@ -1,6 +1,7 @@
 from datetime import datetime as dt
 
-from django.test import SimpleTestCase
+from django.core.exceptions import ValidationError
+from django.test import SimpleTestCase, TestCase
 from django.utils import timezone
 
 from pydis_site.apps.api.models import (
@@ -34,6 +35,43 @@ def test_shows_attributes(self):
         self.assertEqual(repr(self.klass), expected)
 
 
+class NitroMessageLengthTest(TestCase):
+    def setUp(self):
+        self.user = User.objects.create(id=50, name='bill', discriminator=5)
+        self.context = MessageDeletionContext.objects.create(
+            id=50,
+            actor=self.user,
+            creation=dt.utcnow()
+        )
+
+    def test_create(self):
+        message = DeletedMessage(
+            id=46,
+            author=self.user,
+            channel_id=666,
+            content="w"*4000,
+            deletion_context=self.context,
+            embeds=[]
+        )
+
+        try:
+            message.clean_fields()
+        except Exception as e:  # pragma: no cover
+            self.fail(f"Creation of message of length 3950 failed with: {e}")
+
+    def test_create_failure(self):
+        message = DeletedMessage(
+            id=47,
+            author=self.user,
+            channel_id=666,
+            content="w"*4001,
+            deletion_context=self.context,
+            embeds=[]
+        )
+
+        self.assertRaisesRegex(ValidationError, "content':", message.clean_fields)
+
+
 class StringDunderMethodTests(SimpleTestCase):
     def setUp(self):
         self.nomination = Nomination(