Skip to content

Commit

Permalink
Merge pull request #626 from jmmshn/patch-1
Browse files Browse the repository at this point in the history
minor bug fix in remove_docs
  • Loading branch information
munrojm committed Apr 18, 2022
2 parents 3e3c08d + dccf4fe commit 6adef9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/maggma/stores/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def remove_docs(self, criteria: Dict, remove_s3_object: bool = False):
# Can remove up to 1000 items at a time via boto
to_remove_chunks = list(grouper(to_remove, n=1000))
for chunk_to_remove in to_remove_chunks:
objlist = [{"Key": self.sub_dir + obj} for obj in chunk_to_remove]
objlist = [{"Key": f"{self.sub_dir}{obj}"} for obj in chunk_to_remove]
self.s3_bucket.delete_objects(Delete={"Objects": objlist})

@property
Expand Down
12 changes: 10 additions & 2 deletions tests/stores/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,24 @@ def tests_msonable_read_write(s3store):


def test_remove(s3store):
def objects_in_bucket(key):
objs = list(s3store.s3_bucket.objects.filter(Prefix=key))
return key in [o.key for o in objs]

s3store.update([{"task_id": "mp-2", "data": "asd"}])
s3store.update([{"task_id": "mp-4", "data": "asd"}])
s3store.update({"task_id": "mp-5", "data": "aaa"})
assert s3store.query_one({"task_id": "mp-2"}) is not None
assert s3store.query_one({"task_id": "mp-4"}) is not None
assert objects_in_bucket("mp-2")
assert objects_in_bucket("mp-4")

s3store.remove_docs({"task_id": "mp-2"})
s3store.remove_docs({"task_id": "mp-4"}, remove_s3_object=True)

assert objects_in_bucket("mp-2")
assert not objects_in_bucket("mp-4")

assert s3store.query_one({"task_id": "mp-2"}) is None
assert s3store.query_one({"task_id": "mp-4"}) is not None
assert s3store.query_one({"task_id": "mp-5"}) is not None


Expand Down

0 comments on commit 6adef9b

Please sign in to comment.