Skip to content

Commit

Permalink
Updates Burr tracking client to safely encode json
Browse files Browse the repository at this point in the history
There are often missing characters -- this enables the user to safely
encode them. They'll get replaced, but generally that's OK (and
certainly better than failing).
  • Loading branch information
elijahbenizzy committed May 23, 2024
1 parent e10db73 commit 3aa016f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions burr/tracking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,20 @@ def post_application_create(
**future_kwargs: Any,
):
self._ensure_dir_structure(app_id)
self.f = open(os.path.join(self.storage_dir, app_id, self.LOG_FILENAME), "a")
self.f = open(
os.path.join(self.storage_dir, app_id, self.LOG_FILENAME),
"a",
encoding="utf-8",
errors="replace",
)
graph_path = os.path.join(self.storage_dir, app_id, self.GRAPH_FILENAME)
if os.path.exists(graph_path):
logger.info(f"Graph already exists at {graph_path}. Not overwriting.")
return
graph = ApplicationModel.from_application_graph(
application_graph,
).model_dump()
with open(graph_path, "w") as f:
with open(graph_path, "w", encoding="utf-8", errors="replace") as f:
json.dump(graph, f)

metadata_path = os.path.join(self.storage_dir, app_id, self.METADATA_FILENAME)
Expand All @@ -230,7 +235,7 @@ def post_application_create(
if parent_pointer is not None
else None,
).model_dump()
with open(metadata_path, "w") as f:
with open(metadata_path, "w", errors="replace") as f:
json.dump(metadata, f)

def _append_write_line(self, model: pydantic.BaseModel):
Expand Down

0 comments on commit 3aa016f

Please sign in to comment.