-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to upload a compressed S3 file using close() #838
Not able to upload a compressed S3 file using close() #838
Conversation
try: | ||
self.__wrapped__.close() | ||
finally: | ||
if self.__inner != self.__wrapped__: # Don't close again if inner and wrapped are the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a scenario where they are the same, plus calling close a second is a no-op. I think we can do without this conditional (unless there are tests failing without this conditional?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking the code @ddelange . This following test fails if I remove this conditional:
assert len(responses.calls) == 4 # it returns 6 without the conditional
I don't know much about hdfs
; I saw in debug mode that this scenario creates a FileLikeProxy
instance where the wrapper
and inner
are the same; duplicating the close()
call.
Should I adjust the unit test instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know, something to look into but not related to this PR. let's leave it as is :)
smart_open/utils.py
Outdated
|
||
def close(self): | ||
try: | ||
self.__wrapped__.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.__wrapped__.close() | |
return super().close() |
analogous to __exit__
above (maybe some wrapped classes might return a boolean or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ddelange ,
I am trying the super().close()
call but the unit test returns an error:
def close(self):
try:
# return self.__wrapped__.close()
> return super().close()
E AttributeError: 'super' object has no attribute 'close'
../utils.py:230: AttributeError
I noticed that you have __wrapper__.next()
in the class method above. Probably because wrapt.ObjectProxy
does not implement it; similar scenario with the class method close()
).
I am implementing the return part in case close()
return something in different implementation. Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, thanks for checking!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpenkov an important fix, can you cut a bugfix release with this one included?
Thank you @jbarragan-bridge . I will make a release in the next day or so. |
Title: Not able to upload a compressed S3 file using close()
Motivation
We are using smart_open to compress and upload files to s3 without a context manager but since version 7.0.0 the following scenario is NOT longer working because we are using
close()
call without a context manager:e.g.
The problem is that the close() call is only hitting the outer stream and NOT the inner stream. More information can be found in the issue information.
Tests
2 unit tests were added to shows how this change address the compressed file upload during the close() call.
Checklist
Before you create the PR, please make sure you have: