Skip to content

Commit

Permalink
fix: increase FileField maximum length to 380 characters (#5390)
Browse files Browse the repository at this point in the history
### 📣 Summary
Increased the maximum length of FileField models from the default to 380
characters.



### 📖 Description
The maximum length for FileField objects has been increased to 380
characters (100 by default). This change allows longer file paths to be
stored, ensuring compatibility with deeply nested directories or longer
file names that might have been truncated previously.
  • Loading branch information
noliveleger authored Dec 20, 2024
1 parent 570046d commit 507c28f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.15 on 2024-12-19 21:31

from django.db import migrations
import private_storage.fields
import private_storage.storage.files


class Migration(migrations.Migration):

dependencies = [
('markdownx_uploader', '0002_markdownxuploaderfilereference'),
]

operations = [
migrations.AlterField(
model_name='markdownxuploaderfile',
name='content',
field=private_storage.fields.PrivateFileField(
max_length=380,
storage=private_storage.storage.files.PrivateFileSystemStorage(),
upload_to='__markdown_media_files/%Y/%m/%d',
),
),
]
3 changes: 2 additions & 1 deletion kobo/apps/markdownx_uploader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class MarkdownxUploaderFile(models.Model):
content = PrivateFileField(
# Avoid collisions with usernames, which must begin with `[a-z]`
# (see `kpi.forms.USERNAME_REGEX`)
upload_to='__markdown_media_files/%Y/%m/%d'
upload_to='__markdown_media_files/%Y/%m/%d',
max_length=380,
)

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.15 on 2024-12-19 21:31

from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db import migrations

import kobo.apps.openrosa.apps.logger.models.attachment
import kobo.apps.openrosa.apps.logger.models.xform
import kpi.fields.file


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('logger', '0039_populate_counters'),
]

operations = [
migrations.AlterField(
model_name='attachment',
name='media_file',
field=kpi.fields.file.ExtendedFileField(
db_index=True,
max_length=380,
storage=FileSystemStorage(),
upload_to=kobo.apps.openrosa.apps.logger.models.attachment.upload_to,
),
),
migrations.AlterField(
model_name='xform',
name='xls',
field=kpi.fields.file.ExtendedFileField(
max_length=380,
null=True,
storage=FileSystemStorage(),
upload_to=kobo.apps.openrosa.apps.logger.models.xform.upload_to,
),
),
]
7 changes: 6 additions & 1 deletion kobo/apps/openrosa/apps/logger/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ class XForm(AbstractTimeStampedModel):
CLONED_SUFFIX = '_cloned'
MAX_ID_LENGTH = 100

xls = ExtendedFileField(storage=default_storage, upload_to=upload_to, null=True)
xls = ExtendedFileField(
storage=default_storage,
upload_to=upload_to,
null=True,
max_length=380,
)
json = models.TextField(default='')
description = models.TextField(default='', null=True)
xml = models.TextField()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.15 on 2024-12-19 21:31

from django.core.files.storage import FileSystemStorage
from django.db import migrations

import kobo.apps.openrosa.apps.main.models.meta_data
import kpi.fields.file


class Migration(migrations.Migration):

dependencies = [
('main', '0017_userprofile_submissions_suspended'),
]

operations = [
migrations.AlterField(
model_name='metadata',
name='data_file',
field=kpi.fields.file.ExtendedFileField(
blank=True,
max_length=380,
null=True,
storage=FileSystemStorage(),
upload_to=kobo.apps.openrosa.apps.main.models.meta_data.upload_to,
),
),
]
1 change: 1 addition & 0 deletions kobo/apps/openrosa/apps/main/models/meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class MetaData(AbstractTimeStampedModel):
upload_to=upload_to,
blank=True,
null=True,
max_length=380,
)
data_file_type = models.CharField(max_length=255, blank=True, null=True)
file_hash = models.CharField(max_length=50, blank=True, null=True)
Expand Down
2 changes: 1 addition & 1 deletion kpi/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def enketo_flush_cached_preview(server_url, form_id):
@celery_app.task(time_limit=LIMIT_HOURS_23, soft_time_limit=LIMIT_HOURS_23)
def perform_maintenance():
"""
Run daily maintenance tasks. Ensure it cannot run multiple times.
Run daily maintenance tasks.
"""

remove_unused_markdown_files()
Expand Down

0 comments on commit 507c28f

Please sign in to comment.