Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit c9ca88f

Browse files
committed
feat: Improve upload storage path generation for reports
1 parent 7e5a947 commit c9ca88f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

upload/views/uploads.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import uuid
23
from typing import Any, Callable, Dict
34

45
from django.http import HttpRequest, HttpResponseNotAllowed
@@ -56,6 +57,18 @@ def create_upload(
5657
else None
5758
)
5859
archive_service = ArchiveService(repository)
60+
# only Shelter requests are allowed to set their own `storage_path`
61+
serializer.validated_data["external_id"] = uuid.uuid4()
62+
if serializer.validated_data["storage_path"] is None or not is_shelter_request:
63+
path = MinioEndpoints.raw_with_upload_id.get_path(
64+
version="v4",
65+
date=timezone.now().strftime("%Y-%m-%d"),
66+
repo_hash=archive_service.storage_hash,
67+
commit_sha=commit.commitid,
68+
reportid=report.external_id,
69+
uploadid=serializer.validated_data["external_id"],
70+
)
71+
serializer.validated_data["storage_path"] = path
5972
# Create upload record
6073
instance: ReportSession = serializer.save(
6174
report_id=report.id, upload_extras={"format_version": "v1"}, state="started"
@@ -72,18 +85,6 @@ def create_upload(
7285
report_type=report.report_type,
7386
)
7487

75-
# only Shelter requests are allowed to set their own `storage_path`
76-
if instance.storage_path is None or not is_shelter_request:
77-
path = MinioEndpoints.raw_with_upload_id.get_path(
78-
version="v4",
79-
date=timezone.now().strftime("%Y-%m-%d"),
80-
repo_hash=archive_service.storage_hash,
81-
commit_sha=commit.commitid,
82-
reportid=report.external_id,
83-
uploadid=instance.external_id,
84-
)
85-
instance.storage_path = path
86-
instance.save()
8788
trigger_upload_task(repository, commit.commitid, instance, report)
8889
activate_repo(repository)
8990
send_analytics_data(commit, instance, version, analytics_token)

0 commit comments

Comments
 (0)