Skip to content

Bug: CsvTransform loses its encoding and newline options after the first use #8563

Closed

Description

@ArfiArfath21

Expected Behaviour

A CsvTransform keeps the options it was created with, so the same instance gives the same result every time it is applied.

Current Behaviour

CsvTransform.transform() calls .pop() on self.transform_options for encoding and newline. After the first call those options are gone from the instance, and later calls silently fall back to utf-8 and the default newline handling.

The same thing happens inside S3Object when its transformed stream is re-created (for example after another transform(..., in_place=True)), because every transformation is applied again.

Code snippet

import io
import boto3
from botocore import stub
from aws_lambda_powertools.utilities.streaming import S3Object
from aws_lambda_powertools.utilities.streaming.compat import PowertoolsStreamingBody
from aws_lambda_powertools.utilities.streaming.transformations import CsvTransform

transform = CsvTransform(encoding="latin-1")
payload = "name\ncafé\n".encode("latin-1")

client = boto3.client("s3", region_name="us-east-1", aws_access_key_id="x", aws_secret_access_key="x")
with stub.Stubber(client) as s3_stub:
    for _ in range(2):
        body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
        s3_stub.add_response("get_object", {"Body": body})
        print(list(S3Object("bucket", "key", boto3_client=client).transform(transform)))

Possible Solution

Copy the options inside transform() before popping encoding and newline. I have a small fix with a regression test ready.

Steps to Reproduce

Run the snippet above. The first iteration prints [{'name': 'café'}]; the second raises UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9.

Powertools for AWS Lambda (Python) version

develop (1d4f145, 3.36.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi


Disclosure: I found this while reviewing the streaming utility with the help of an AI assistant (Claude Code). I ran the snippet above myself against develop.

Activity

  1. boring-cyborg commented on Oct 16, 2026

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

  2. powertools-for-aws-oss-automation commented on Oct 16, 2026

    @powertools-for-aws-oss-automation

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out our GitHub Discussions: Join the conversation

  3. powertools-for-aws-oss-automation commented on Oct 17, 2026

    @powertools-for-aws-oss-automation

    Warning

    This issue is now closed. Please be mindful that future comments are hard for our team to see.
    If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  4. github-actions commented on Oct 22, 2026

    @github-actions
    Contributor

    This is now released under 3.37.0 version!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions