Fix database error with long domain names in scan results directory #1520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Database Error with Long Domain Names
Resolves #1519 -
django.db.utils.DataError: value too long for type character varying(100)Bug
Django crashes with a database error when scanning domains with long names. This happens during scan initialization when saving the
ScanHistoryobject - specifically when theresults_dirfield exceeds PostgreSQL's 100-character varchar limit.Root Cause
The
results_dirfield was constructed using domain names directly:With long domains, this easily breaks the 100-character PostgreSQL limit:
Fix
Switched from using unpredictable domain names to predictable domain IDs in paths:
Before:
domain-name.example.com_123(unpredictable length)After:
domain_42_scan_123(always <50 chars)Changes Made
Added utility function for consistent path generation:
Updated scan initialization to use the new function:
Increased database field limit from 100 to 500 characters as a safety net
Added migration to update existing installations safely
Files Changed
web/reNgine/tasks.py- Updated scan initialization logicweb/reNgine/common_func.py- Added utility functionweb/startScan/models.py- Increased field lengthweb/startScan/migrations/0003_increase_results_dir_length.py- Database migrationTesting
The migration is safe to run on production - it only increases field capacity and the new naming scheme ensures paths stay well under limits.
To test:
Then try scanning a domain with a long name (>32 characters) - it should work without database errors.