Repository navigation
fix(streaming): close S3Object when transform doesn't return an IO stream - #8898
Open
caiotheodoro wants to merge 1 commit into
Open
caiotheodoro wants to merge 1 commit into
caiotheodoro wants to merge 1 commit into
Conversation
…ream CsvTransform returns a csv.DictReader, which has no close() or closed. After reading a row, S3Object.closed and close() raised AttributeError. Only call close() on the transformed stream when it exposes one, and fall back to the raw stream's state for closed when it doesn't. closes aws-powertools#8886
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
No acknowledgement section found. Please make sure you used the template to open a PR and didn't remove the acknowledgment section. Check the template at |
|
This branch has not been deployed
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.



Draft PR — not filed
Title:
fix(streaming): close S3Object when transform doesn't return an IO streamIssue number: closes #8886
Summary
Changes
S3Objectassumed every transformed stream implementsIO[bytes], butCsvTransformreturns acsv.DictReader, which has neitherclose()norclosed.close()now only callsclose()on the transformed stream when itexposes one (the raw stream is always closed first, releasing the underlying
resource), and
closedfalls back toraw_stream.closedwhen the transformedstream doesn't report its own state. Gzip/zip transforms are unaffected — they
still return real IO objects whose
close/closedare honoured.User experience
Before: after reading a row from
S3Object(..., is_csv=True),obj.closedraised
AttributeError: 'DictReader' object has no attribute 'closed'andobj.close()(includingwithexit) raisedAttributeError: 'DictReader' object has no attribute 'close'— plain CSV, gzip+CSV, and in-placeCsvTransformall affected.After:
closedcorrectly reports the raw stream's state andclose()releasesthe object cleanly.
Verification
tests/functional/streaming/_boto3/test_s3_object.py:is_csv(raw andgzip), context-manager exit, and in-place
CsvTransform. All 4 fail ondevelopwith the reportedAttributeError; all pass with the fix.pytest tests/functional/streaming/: 86 passed.ruff format --check,ruff check,mypy: clean on changed files.triage— happy to hold for maintainer triage.AI-assisted: I reproduced the bug, wrote the fix and tests, and ran the checks
above myself.