fix: CSV export crash due to inconsistent dict keys#253
Open
SylvainM98 wants to merge 1 commit intomegadose:masterfrom
Open
fix: CSV export crash due to inconsistent dict keys#253SylvainM98 wants to merge 1 commit intomegadose:masterfrom
SylvainM98 wants to merge 1 commit intomegadose:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
holehe email@test.com -Ccrashes with:Root cause
export_csv()usesdata[0].keys()asDictWriterfieldnames, but modules and thelaunch_moduleerror handler produce dicts with different key sets:method,frequent_rate_limit(noerror)error(nomethod, nofrequent_rate_limit)When
data[0]is an error dict (after alphabetical sort), fieldnames missmethodandfrequent_rate_limit, causing the crash on subsequent rows.Fix
dict.fromkeys()(preserves insertion order)methodandfrequent_rate_limitfields tolaunch_moduleerror handlerrestval=""andextrasaction="ignore"as safety netsTesting
Tested with multiple email addresses — CSV now exports correctly with all 10 columns.
Fixes #44 #45