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

chore(weave): Cleanup save object basic #3015

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions weave/trace/weave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,13 +1335,13 @@ def _save_object_basic(
"""Directly saves an object to the weave server and attach
the ref to the object. This is the lowest level object saving logic.
"""
orig_val = val
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to top for clarity


# The WeaveTable case is special because object saving happens inside
# _save_object_nested and it has a special table_ref -- skip it here.
if getattr(val, "_is_dirty", False) and not isinstance(val, WeaveTable):
val.ref = None

is_opdef = is_op(val)
orig_val = val
val = map_to_refs(val)
if isinstance(val, ObjectRef):
if ALLOW_MIXED_PROJECT_REFS:
Expand All @@ -1352,9 +1352,6 @@ def _save_object_basic(
return val
val = orig_val

# `to_json` is mostly fast, except for CustomWeaveTypes
# which incur network costs to serialize the payload

if name is None:
serializer = get_serializer_for_obj(val)
if serializer:
Expand All @@ -1366,6 +1363,8 @@ def _save_object_basic(
name = sanitize_object_name(name)

def send_obj_create() -> ObjCreateRes:
# `to_json` is mostly fast, except for CustomWeaveTypes
# which incur network costs to serialize the payload
Comment on lines +1366 to +1367
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved comment closer to code for clarity

json_val = to_json(val, self._project_id(), self)
req = ObjCreateReq(
obj=ObjSchemaForInsert(
Expand All @@ -1377,21 +1376,20 @@ def send_obj_create() -> ObjCreateRes:
return self.server.obj_create(req)

res_future: Future[ObjCreateRes] = self.future_executor.defer(send_obj_create)

digest_future: Future[str] = self.future_executor.then(
[res_future], lambda res: res[0].digest
)

ref: Ref
if is_opdef:
if is_op(orig_val):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline

ref = OpRef(self.entity, self.project, name, digest_future)
else:
ref = ObjectRef(self.entity, self.project, name, digest_future)

# Attach the ref to the object
try:
set_ref(orig_val, ref)
except:
except Exception:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Don't worry if we can't set the ref.
# This can happen for primitive types that don't have __dict__
pass
Expand Down
Loading