Skip to content

Commit

Permalink
zopen: add explicit encoding to read_json; explicit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Feb 6, 2025
1 parent ff6d195 commit 02520e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/maggma/stores/mongolike.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def connect(self, force_reset: bool = False):

# create the .json file if it does not exist
if not self.read_only and not Path(self.paths[0]).exists():
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
with zopen(self.paths[0], mode="wt", encoding=self.encoding) as f:
data: list[dict] = []
bytesdata = orjson.dumps(data)
f.write(bytesdata.decode("utf-8"))
Expand All @@ -711,7 +711,7 @@ def read_json_file(self, path) -> list:
Args:
path: Path to the JSON file to be read
"""
with zopen(path, "rt") as f:
with zopen(path, mode="rt", encoding=self.encoding) as f:
data = f.read()
data = data.decode() if isinstance(data, bytes) else data
objects = bson.json_util.loads(data) if "$oid" in data else orjson.loads(data)
Expand Down Expand Up @@ -761,7 +761,7 @@ def update_json_file(self):
"""
Updates the json file when a write-like operation is performed.
"""
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
with zopen(self.paths[0], mode="wt", encoding=self.encoding) as f:
data = list(self.query())
for d in data:
d.pop("_id")
Expand Down

0 comments on commit 02520e8

Please sign in to comment.