Skip to content

Commit

Permalink
use bson.json_util.loads for S3 (#933)
Browse files Browse the repository at this point in the history
* use bson.json_util.loads for S3

* pre-commit fixes
  • Loading branch information
tschaume authored Sep 11, 2024
1 parent a9e1bc5 commit 2c89d4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions mp_api/client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
API v3 to enable the creation of data structures and pymatgen objects using
Materials Project data.
"""

from __future__ import annotations

import itertools
Expand All @@ -21,6 +22,7 @@
from urllib.parse import quote, urljoin

import requests
from bson import json_util
from emmet.core.utils import jsanitize
from monty.json import MontyDecoder
from pydantic import BaseModel, create_model
Expand Down Expand Up @@ -494,7 +496,7 @@ def _query_resource(
)
suffix = suffix.replace("_", "-")

# Paginate over all entried in the bucket.
# Paginate over all entries in the bucket.
# This will have to change for when a subset of entries from
# the DB is needed.
is_tasks = "tasks" in suffix
Expand All @@ -516,7 +518,9 @@ def _query_resource(
if key:
keys.append(key)

decoder = MontyDecoder().decode if self.monty_decode else json.loads
decoder = (
MontyDecoder().decode if self.monty_decode else json_util.loads
)

# Multithreaded function inputs
s3_params_list = {
Expand Down
4 changes: 3 additions & 1 deletion mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,9 @@ def get_charge_density_from_material_id(
if self.use_document_model
else x["last_updated"], # type: ignore
)
task_id = latest_doc.task_id if self.use_document_model else latest_doc["task_id"]
task_id = (
latest_doc.task_id if self.use_document_model else latest_doc["task_id"]
)
return self.get_charge_density_from_task_id(task_id, inc_task_doc)

def get_download_info(self, material_ids, calc_types=None, file_patterns=None):
Expand Down

0 comments on commit 2c89d4c

Please sign in to comment.