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

update gridfs store #381

Merged
merged 5 commits into from
Jan 21, 2021
Merged

update gridfs store #381

merged 5 commits into from
Jan 21, 2021

Conversation

gpetretto
Copy link
Contributor

Currently the GridFSStore does not allow to access data from gridfs collections that were not generated with maggma, since they will not contain the metadata value. This PR aims to allow the retrieval of data from a generic gridfs collection.

In its current form however the method returns the bytes extracted from the gridfs and not a dict, as required by the API. In general this could happen if this json.loads fails:
https://github.com/materialsproject/maggma/blob/master/src/maggma/stores/gridfs.py#L209

                try:
                    data = json.loads(data)
                except Exception:
                    pass

Would you agree to also replace this with:

                try:
                    data = json.loads(data)
                except Exception:
                    if not isinstance(data, dict):
                        data = dict(data=data)

?

@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #381 (cde6c91) into master (e0c319b) will decrease coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #381      +/-   ##
==========================================
- Coverage   86.85%   86.74%   -0.12%     
==========================================
  Files          28       28              
  Lines        2222     2225       +3     
==========================================
  Hits         1930     1930              
- Misses        292      295       +3     
Impacted Files Coverage Δ
src/maggma/stores/gridfs.py 90.90% <100.00%> (+1.54%) ⬆️
src/maggma/stores/mongolike.py 82.12% <0.00%> (-1.91%) ⬇️
src/maggma/cli/serial.py 79.31% <0.00%> (ø)
src/maggma/cli/source_loader.py 70.11% <0.00%> (ø)
src/maggma/cli/multiprocessing.py 94.64% <0.00%> (ø)
src/maggma/cli/__init__.py 92.00% <0.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4456fb1...cde6c91. Read the comment docs.

@shyamd
Copy link
Contributor

shyamd commented Jan 16, 2021

You might also include the key field and the last_updated data from the index. Please update the docstrings to make it clear that is what gets returned.

@gpetretto
Copy link
Contributor Author

@shyamd I hope I interpreted your suggestion correctly.
I also added a test for this specific use case.

@shyamd shyamd merged commit 09972b8 into materialsproject:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants