Skip to content

Fix FileUpload.copy() to prevent title length exceeding 100 chars#13968

Merged
Maffooch merged 1 commit intoDefectDojo:bugfixfrom
valentijnscholten:fix-fileupload-copy-title-length-11314
Dec 29, 2025
Merged

Fix FileUpload.copy() to prevent title length exceeding 100 chars#13968
Maffooch merged 1 commit intoDefectDojo:bugfixfrom
valentijnscholten:fix-fileupload-copy-title-length-11314

Conversation

@valentijnscholten
Copy link
Copy Markdown
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.

Comment thread dojo/tools/tenable/csv_format.py Outdated
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
Copy Markdown
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

@Maffooch Maffooch merged commit 6d830c1 into DefectDojo:bugfix Dec 29, 2025
150 checks passed
Maffooch pushed a commit to valentijnscholten/django-DefectDojo that referenced this pull request Feb 16, 2026
…fectDojo#13968)

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.
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

5 participants