Skip to content

Conversation

@fschledorn
Copy link

@fschledorn fschledorn commented Aug 14, 2025

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 ScanHistory object - specifically when the results_dir field exceeds PostgreSQL's 100-character varchar limit.

Root Cause

The results_dir field was constructed using domain names directly:

scan.results_dir = f'{results_dir}/{domain.name}_{scan.id}'

With long domains, this easily breaks the 100-character PostgreSQL limit:

/usr/src/app/scan_results/really-really-long-subdomain-name.example.com_123
└─ 86+ characters (approaching/exceeding 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

  1. Added utility function for consistent path generation:

    def get_scan_results_dir(results_base_dir, domain_id, scan_id):
        return f'{results_base_dir}/domain_{domain_id}_scan_{scan_id}'
  2. Updated scan initialization to use the new function:

    scan.results_dir = get_scan_results_dir(results_dir, domain.id, scan.id)
  3. Increased database field limit from 100 to 500 characters as a safety net

  4. Added migration to update existing installations safely

Files Changed

  • web/reNgine/tasks.py - Updated scan initialization logic
  • web/reNgine/common_func.py - Added utility function
  • web/startScan/models.py - Increased field length
  • web/startScan/migrations/0003_increase_results_dir_length.py - Database migration

Testing

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:

python manage.py migrate startScan

Then try scanning a domain with a long name (>32 characters) - it should work without database errors.

Resolves yogeshojha#1519 - django.db.utils.DataError: value too long for type character varying(100)
@github-actions
Copy link
Contributor

Woohoo @fschledorn! 🎉 You've just dropped some hot new code! 🔥

Hang tight while we review this! You rock! 🤘

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.

bug: DataError: value too long for type character varying(100) when initiating a scan

1 participant