-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix s3 delete_many #38
Conversation
Couldn't find any documentation around this issue, but I empirically discovered that `delete_objects` with an empty array causes the request to fail. Also, this is a valid optimization anyway.
Add a quick test. |
tests/test_s3.py
Outdated
def assert_not_called(*args, **kwargs): | ||
assert(False) | ||
|
||
monkeypatch.setattr(annex._client, 'delete_objects', assert_not_called) |
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.
why not just use a mock
and actually assert it's not called, instead of this thing?
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.
because I didn't think it was worth adding a dependency
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.
what dependency? isn't mock in python3?
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.
yes but tests run also on py2
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 think adding that dev dep is fine/better
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.
mkay
flask_annex/s3.py
Outdated
@@ -40,11 +40,15 @@ def delete(self, key): | |||
self._client.delete_object(Bucket=self._bucket_name, Key=key) | |||
|
|||
def delete_many(self, keys): | |||
objects = tuple({'Key': key} for key in keys) |
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.
probably worth noting that you're doing this first because keys
may be an iterable
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.
one last nit, then
tests/test_s3.py
Outdated
@@ -12,6 +12,7 @@ | |||
|
|||
try: | |||
import boto3 | |||
from mock import Mock |
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.
install this unconditionally and take this out of the try/catch imo
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.
sure
Couldn't find any documentation around this issue, but I empirically discovered that
delete_objects
with an empty array causes the request to fail. Also, this is a valid optimization anyway.