fix(examples): consistent CSV schema in survey_agent#5689
Merged
Conversation
write_to_csv had three issues: writeheader() was dead code (the os.path.exists() check ran after aiofiles.open(filename, "a") already created the file), AsyncWriter has no writeheader() and was being mis-constructed (its second positional arg is dialect, not fieldnames), and the disqualify and success paths wrote disjoint column sets so rows would be misaligned even if a header existed. Use AsyncDictWriter with a fixed CSV_COLUMNS tuple, decide on the header by checking the file pointer position after opening in append mode, and normalize the disqualify key to disqualification_reason. Populate name on the success path from userdata so both paths fill the name column.
tinalenguyen
approved these changes
May 12, 2026
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.
Description
Fix three bugs in
examples/survey/survey_agent.py'swrite_to_csv: the header was never written (os.path.existsran afteraiofiles.open(..., "a")had already created the file),AsyncWriterhas nowriteheader()and was being mis-constructed (its second positional arg isdialect, not fieldnames), and the disqualify and success paths used disjoint column sets.Changes
AsyncDictWriterwith a fixedCSV_COLUMNStuple (extrasaction="ignore").await csvfile.tell() == 0after opening in append mode.disqualification_reason(was"disqualification reason").nameon the success path fromuserdata.candidate_name.Testing
make lint(ruff) passes locally.