Skip to content

fix: CSV export crash due to inconsistent dict keys#253

Open
SylvainM98 wants to merge 1 commit intomegadose:masterfrom
SylvainM98:fix/csv-export-fieldnames
Open

fix: CSV export crash due to inconsistent dict keys#253
SylvainM98 wants to merge 1 commit intomegadose:masterfrom
SylvainM98:fix/csv-export-fieldnames

Conversation

@SylvainM98
Copy link

@SylvainM98 SylvainM98 commented Mar 2, 2026

Problem

holehe email@test.com -C crashes with:

ValueError: dict contains fields not in fieldnames: 'frequent_rate_limit', 'method'

Root cause

export_csv() uses data[0].keys() as DictWriter fieldnames, but modules and the launch_module error handler produce dicts with different key sets:

  • Modules return: method, frequent_rate_limit (no error)
  • Error handler returns: error (no method, no frequent_rate_limit)

When data[0] is an error dict (after alphabetical sort), fieldnames miss method and frequent_rate_limit, causing the crash on subsequent rows.

Fix

  • Collect union of all keys across all result dicts using dict.fromkeys() (preserves insertion order)
  • Add missing method and frequent_rate_limit fields to launch_module error handler
  • Add restval="" and extrasaction="ignore" as safety nets

Testing

Tested with multiple email addresses — CSV now exports correctly with all 10 columns.

Fixes #44 #45

DictWriter used data[0].keys() as fieldnames, but the error handler
in launch_module() produces dicts with different keys than the
individual modules (missing 'method' and 'frequent_rate_limit',
extra 'error' field).

When data[0] happens to be an error dict (sorted alphabetically),
the fieldnames miss 'method' and 'frequent_rate_limit', causing:
  ValueError: dict contains fields not in fieldnames

Fix:
- Use union of all keys from all result dicts as fieldnames
- Add missing fields to launch_module error handler dict
- Add restval="" and extrasaction="ignore" as safety nets

Fixes #44 megadose#45
@SylvainM98 SylvainM98 closed this Mar 2, 2026
@SylvainM98 SylvainM98 reopened this Mar 2, 2026
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.

1 participant