Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Change attachment.size to not be nullable.
Tim Abbottf98d244ed642
diff --git a/zerver/migrations/0289_tighten_attachment_size.py b/zerver/migrations/0289_tighten_attachment_size.pynew file mode 100644index 00000000000..6ebf4d41a13--- /dev/null+++ b/zerver/migrations/0289_tighten_attachment_size.py@@ -0,0 +1,25 @@+# Generated by Django 2.2.13 on 2020-06-20 19:57++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('zerver', '0288_reaction_unique_on_emoji_code'),+ ]++ operations = [+ migrations.AlterField(+ model_name='archivedattachment',+ name='size',+ field=models.IntegerField(default=0),+ preserve_default=False,+ ),+ migrations.AlterField(+ model_name='attachment',+ name='size',+ field=models.IntegerField(default=0),+ preserve_default=False,+ ),+ ]diff --git a/zerver/models.py b/zerver/models.pyindex f7204660bc2..0969d882dc9 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -2053,7 +2053,8 @@ class AbstractAttachment(models.Model):create_time: datetime.datetime = models.DateTimeField(default=timezone_now, db_index=True,)- size: Optional[int] = models.IntegerField(null=True)+ # Size of the uploaded file, in bytes+ size: int = models.IntegerField()# Whether this attachment has been posted to a public stream, and# thus should be available to all non-guest users in thediff --git a/zerver/tests/test_attachments.py b/zerver/tests/test_attachments.pyindex 7b8ec3b832a..dcef604ca96 100644--- a/zerver/tests/test_attachments.py+++ b/zerver/tests/test_attachments.py@@ -11,7 +11,8 @@ class AttachmentsTests(ZulipTestCase):super().setUp()user_profile = self.example_user('cordelia')self.attachment = Attachment.objects.create(- file_name='test.txt', path_id='foo/bar/test.txt', owner=user_profile)+ file_name='test.txt', path_id='foo/bar/test.txt', owner=user_profile,+ size=512)def test_list_by_user(self) -> None:user_profile = self.example_user('cordelia')diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex e909c39b804..ce4acf84e78 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -795,12 +795,12 @@ class ScrubRealmTest(ZulipTestCase):self.send_stream_message(king, "Shakespeare")Attachment.objects.filter(realm=zulip).delete()- Attachment.objects.create(realm=zulip, owner=iago, path_id="a/b/temp1.txt")- Attachment.objects.create(realm=zulip, owner=othello, path_id="a/b/temp2.txt")+ Attachment.objects.create(realm=zulip, owner=iago, path_id="a/b/temp1.txt", size=512)+ Attachment.objects.create(realm=zulip, owner=othello, path_id="a/b/temp2.txt", size=512)Attachment.objects.filter(realm=lear).delete()- Attachment.objects.create(realm=lear, owner=cordelia, path_id="c/d/temp1.txt")- Attachment.objects.create(realm=lear, owner=king, path_id="c/d/temp2.txt")+ Attachment.objects.create(realm=lear, owner=cordelia, path_id="c/d/temp1.txt", size=512)+ Attachment.objects.create(realm=lear, owner=king, path_id="c/d/temp2.txt", size=512)CustomProfileField.objects.create(realm=lear)