Skip to content

Conversation

@valentijnscholten
Copy link
Member

@valentijnscholten valentijnscholten commented Dec 23, 2025

Not sure if we want to keep the copy functionality, but here's a quick fix for Fixes #11314

Problem

When copying a Test with attached files, the copy operation fails with a database error if any file has a title that is 84+ characters long. The error occurs because the FileUpload.copy() method appends - clone-{hash} (17 characters) to the title without checking if it would exceed the database max_length constraint of 100 characters.

Solution

Modified the copy() method in FileUpload to truncate the original title before appending the clone suffix, ensuring the total length never exceeds 100 characters.

Changes

  • Calculate the clone suffix length dynamically
  • Truncate the original title to ensure total length ≤ 100 characters
  • Append the suffix to create a unique title within database constraints

Testing

  • Verified the fix handles edge cases where titles are already at or near the limit
  • Works correctly even when copying files that were already copied (which may already have clone suffixes)

Error Before Fix

django.db.utils.DataError: value too long for type character varying(100)

After Fix

File titles are properly truncated to fit within the 100 character limit, allowing tests to be copied successfully with all attached files.

Fixes DefectDojo#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.
@valentijnscholten valentijnscholten force-pushed the fix-fileupload-copy-title-length-11314 branch from 35065da to 03e1c39 Compare December 24, 2025 10:35
@github-actions github-actions bot removed the parser label Dec 24, 2025
Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy Test fails because attached file name is too long >100 chars

3 participants