Skip to content
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

Minor bug fixes to S3Store #253

Merged
merged 12 commits into from
Aug 21, 2020
4 changes: 2 additions & 2 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mkdocs==1.1.2
mkdocs-material==5.5.7
mkdocs-minify-plugin==0.3.0
mkdocstrings==0.12.2
pymdown-extensions==7.1
mkdocstrings==0.13.0
pymdown-extensions==8.0
2 changes: 1 addition & 1 deletion requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
uvicorn==0.11.8
boto3==1.14.39
boto3==1.14.47
hvac==0.10.5
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"sshtunnel>=0.1.5",
"msgpack-python>=0.5.6",
],
extras_require={"vault": ["hvac>=0.9.5"], "S3": ["boto3==1.14.39"]},
extras_require={"vault": ["hvac>=0.9.5"], "S3": ["boto3==1.14.47"]},
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
Expand Down
10 changes: 8 additions & 2 deletions src/maggma/stores/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import msgpack # type: ignore
from monty.dev import deprecated
from monty.msgpack import default as monty_default
from monty.msgpack import object_hook as monty_object_hook

from maggma.core import Sort, Store
from maggma.utils import grouper, to_isoformat_ceil_ms
Expand Down Expand Up @@ -181,7 +180,12 @@ def query(
data = zlib.decompress(data)
# requires msgpack-python to be installed to fix string encoding problem
# https://github.com/msgpack/msgpack/issues/121
yield msgpack.unpackb(data, object_hook=monty_object_hook, raw=False)
# During recursion
# msgpack.unpackb goes as deep as possible during reconstruction
# MontyDecoder().process_decode only goes until it finds a from_dict
# as such, we cannot just use msgpack.unpackb(data, object_hook=monty_object_hook, raw=False)
# Should just return the unpacked object then let the user run process_decoded
yield msgpack.unpackb(data, raw=False)

def distinct(
self, field: str, criteria: Optional[Dict] = None, all_exist: bool = False
Expand Down Expand Up @@ -255,6 +259,8 @@ def update(self, docs: Union[List[Dict], Dict], key: Union[List, str, None] = No
field is to be used
"""
search_docs = []
if not isinstance(docs, list):
docs = [docs]

if isinstance(key, list):
search_keys = key
Expand Down
4 changes: 3 additions & 1 deletion tests/stores/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ def tests_msonable_read_write(s3store):
dd = s3store.as_dict()
s3store.update([{"task_id": "mp-2", "data": dd}])
res = s3store.query_one({"task_id": "mp-2"})
assert isinstance(res["data"], S3Store)
assert res["data"]["@module"] == "maggma.stores.aws"


def test_remove(s3store):
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
Expand All @@ -145,6 +146,7 @@ def test_remove(s3store):

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


def test_close(s3store):
Expand Down