Skip to content

Commit 6d830c1

Browse files
Fix FileUpload.copy() to prevent title length exceeding 100 chars (#13968)
Fixes #11314 When copying a FileUpload, the copy() method appends ' - clone-{hash}' (17 characters) to the title without checking if it would exceed the database max_length constraint of 100 characters. This causes a DataError when copying tests with files that have long names. The fix truncates the original title before appending the clone suffix to ensure the total length never exceeds 100 characters.
1 parent b6481ba commit 6d830c1

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

dojo/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,12 @@ def delete(self, *args, **kwargs):
803803
def copy(self):
804804
copy = copy_model_util(self)
805805
# Add unique modifier to file name
806-
copy.title = f"{self.title} - clone-{str(uuid4())[:8]}"
806+
# Truncate title to ensure it doesn't exceed max_length (100) when appending suffix
807+
# Suffix " - clone-{8 chars}" is 17 characters, so truncate to 83 chars
808+
clone_suffix = f" - clone-{str(uuid4())[:8]}"
809+
max_title_length = 100 - len(clone_suffix)
810+
truncated_title = self.title[:max_title_length] if len(self.title) > max_title_length else self.title
811+
copy.title = f"{truncated_title}{clone_suffix}"
807812
# Create new unique file name
808813
current_url = self.file.url
809814
_, current_full_filename = current_url.rsplit("/", 1)

0 commit comments

Comments
 (0)