Skip to content

fix(streaming): keep line breaks inside quoted fields in CsvTransform - #8924

Open
sumedh-aerram wants to merge 1 commit into
aws-powertools:developfrom
sumedh-aerram:fix/streaming-csv-quoted-newlines
Open

sumedh-aerram wants to merge 1 commit into
aws-powertools:developfrom
sumedh-aerram:fix/streaming-csv-quoted-newlines

Conversation

@sumedh-aerram

Copy link
Copy Markdown
Contributor

Issue number:

closes #8923

Summary

Changes

CsvTransform now defaults newline to "" instead of None when it wraps the S3 stream in io.TextIOWrapper, as the csv module docs require. Line breaks inside quoted fields reach csv.DictReader untouched. Row endings (\n, \r\n, \r) are still handled by the csv reader.

The streaming docs now describe the encoding and newline options, including newline=None for anyone who wants the old translation to \n. The agent skill reference for streaming is regenerated from that page. Only the streaming reference is included; make agent-skill also touches logger.md, which is unrelated drift on develop.

User experience

Before: a quoted field "line one\r\nline two" came back as "line one\nline two", and "carriage\rreturn" as "carriage\nreturn". After: both come back exactly as stored.

This changes output only for CSV files that have \r inside quoted fields. Callers who want the previous behaviour can pass CsvTransform(newline=None), which is now documented.

Verification

  • New functional test test_csv_transform_keeps_line_breaks_inside_quoted_fields reads a stubbed S3 object through the public S3Object(...).transform(CsvTransform()) API. It fails on develop and passes with the fix.
  • tests/functional/streaming: passed on Python 3.10, 3.12 and 3.14. Full pytest tests/functional tests/unit -m "not perf": 4180 passed. ruff format --check, ruff check, mypy aws_lambda_powertools examples and markdownlint-cli 0.34.0 on docs/utilities/streaming.md pass.
  • Not validated against a real S3 object. The change is in the text decoding of the stream, and the stubbed body uses the same StreamingBody type boto3 returns.

I used an AI assistant (Claude) to help write this change. I ran every check above and reviewed the diff myself.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sumedh-aerram
sumedh-aerram requested a review from a team as a code owner November 28, 2026 23:20
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 28, 2026
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation streaming tests labels Nov 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

documentation Improvements or additions to documentation size/S Denotes a PR that changes 10-29 lines, ignoring generated files. streaming tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CsvTransform changes line breaks inside quoted fields

1 participant