Skip to content

gh-157678: Allow csv.Sniffer to inspect large fields - #157689

Open
GruffElixir wants to merge 1 commit into
python:mainfrom
GruffElixir:fix-csv-sniffer-field-limit
Open

GruffElixir wants to merge 1 commit into
python:mainfrom
GruffElixir:fix-csv-sniffer-field-limit

Conversation

@GruffElixir

Copy link
Copy Markdown
Contributor

gh-157678

csv.Sniffer.sniff() uses the CSV reader for trial parsing, so a sample containing a field larger than csv.field_size_limit() currently makes every candidate parse fail and raises csv.Error. Temporarily raising the parser limit to the sample length lets Sniffer determine the dialect, then restores the caller's configured limit in a finally block.

Tests:

  • python Lib/test/test_csv.py TestSniffer
  • focused regression for a 200,000-character field with a configured limit of 100
  • git diff --check

Copilot AI lite review requested due to automatic review settings September 17, 2026 16:00
@python-cla-bot

python-cla-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@GruffElixir
GruffElixir force-pushed the fix-csv-sniffer-field-limit branch from 9020c23 to 1bae00d Compare September 17, 2026 16:02

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This temporarily changes the interpreter-wide CSV field limit, so concurrent readers can observe the raised limit, and a concurrent field_size_limit() update can also get overwritten by the finally restore. Could Sniffer avoid mutating the global limit for its trial parses, or otherwise isolate this so sniffing doesn't change another thread's parser behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants