Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 89 additions & 125 deletions doc/release/RELEASE-NOTES.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/django/api/migrations/0172_increase_path_max_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.17 on 2025-07-02 21:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0171_added_origin_source_field'),
]

operations = [
migrations.AlterField(
model_name='downloadlog',
name='path',
field=models.CharField(help_text='The requested resource path', max_length=4096),
),
]
2 changes: 1 addition & 1 deletion src/django/api/models/download_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DownloadLog(models.Model):
help_text='The User account that made the request'
)
path = models.CharField(
max_length=2083,
max_length=4096,
null=False,
help_text='The requested resource path'
)
Expand Down
12 changes: 12 additions & 0 deletions src/django/api/serializers/log_download_query_params.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import (
CharField,
IntegerField,
Serializer,
)

from api.models.download_log import DownloadLog


class LogDownloadQueryParamsSerializer(Serializer):
path = CharField(required=True)
record_count = IntegerField(required=True)

def validate_path(self, value):
max_length = DownloadLog._meta.get_field('path').max_length
if len(value) > max_length:
raise ValidationError(
f"Path length must not exceed "
f"{max_length} characters."
)
return value
32 changes: 32 additions & 0 deletions src/django/api/tests/test_log_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,35 @@ def test_creates_record(self):
log = DownloadLog.objects.first()
self.assertEqual(expected_path, log.path)
self.assertEqual(expected_record_count, log.record_count)

def test_path_max_length(self):
DownloadLog.objects.all().delete()
self.client.login(email=self.email, password=self.password)
max_length = DownloadLog._meta.get_field('path').max_length
expected_record_count = 42
# Create a path exactly at max length.
path = "a" * max_length
url = "{}?{}={}&{}={}".format(
self.path,
LogDownloadQueryParams.PATH,
path,
LogDownloadQueryParams.RECORD_COUNT,
expected_record_count,
)
response = self.client.post(url)
self.assertEqual(204, response.status_code)

# Test that path exceeding max_length raises error on full_clean.
expected_error = "Path length must not exceed 4096 characters."
too_long_path = "a" * (max_length + 1)
url = "{}?{}={}&{}={}".format(
self.path,
LogDownloadQueryParams.PATH,
too_long_path,
LogDownloadQueryParams.RECORD_COUNT,
expected_record_count,
)
response = self.client.post(url)
self.assertEqual(response.status_code, 400)
self.assertIn('path', response.data)
self.assertEqual(response.data['path'][0], expected_error)
2 changes: 2 additions & 0 deletions src/django/api/views/log_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def log_download(request):
raise ValidationError(params.errors)

path = request.query_params.get(LogDownloadQueryParams.PATH)

record_count = request.query_params.get(
LogDownloadQueryParams.RECORD_COUNT
)

DownloadLog.objects.create(
user=request.user,
path=path,
Expand Down