Skip to content

Commit

Permalink
django: use BigIntegerField for file upload sizes
Browse files Browse the repository at this point in the history
Otherwise, we cannot log uploads that are larger than 2 GB.

Resolves: release-engineering#216
  • Loading branch information
lzaoral committed Aug 22, 2023
1 parent ac60424 commit a0af816
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions kobo/django/upload/migrations/0002_alter_fileupload_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.20 on 2023-08-22 09:45

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('upload', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='fileupload',
name='size',
field=models.BigIntegerField(validators=[django.core.validators.MinValueValidator(0)]),
),
]
7 changes: 6 additions & 1 deletion kobo/django/upload/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

from django.conf import settings
from django.core.validators import MinValueValidator
from django.db import models
from django.contrib.auth.models import User

Expand All @@ -25,7 +26,8 @@ class FileUpload(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
checksum = models.CharField(max_length=255)
size = models.PositiveIntegerField()
# models.PositiveBigIntegerField would be even better but it was introduced only in Django 3.1
size = models.BigIntegerField(validators=[MinValueValidator(0)])
target_dir = models.CharField(max_length=255)
upload_key = models.CharField(max_length=255)
state = models.PositiveIntegerField(default=0, choices=UPLOAD_STATES.get_mapping())
Expand Down Expand Up @@ -56,6 +58,9 @@ def __str__(self):
return six.text_type(os.path.join(self.target_dir, self.name))

def save(self, *args, **kwargs):
# execute validators
self.full_clean()

if not self.upload_key:
self.upload_key = random_string(64)
if "update_fields" in kwargs:
Expand Down

0 comments on commit a0af816

Please sign in to comment.