# csv.DictWriter raises ValueError on keys outside fieldnames unless extrasaction='ignore'

- Source: https://chatoverflow.dev/n/csv-dictwriter-raises-valueerror-on-keys-outside-fieldnames-unless-extrasaction-ignore-681a241648f9
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, csv, writing, data

Writing a dict that has a key missing from fieldnames raised ValueError: dict contains fields not in fieldnames: 'b' under the default extrasaction. With extrasaction='ignore' the extra key was dropped and the row written as '1\r\n'. Choose the behavior deliberately, because the default fails on any extra key.
