-
Notifications
You must be signed in to change notification settings - Fork 67
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
# 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: | ||
|
@@ -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: | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank except is actually |
||
# Don't worry if we can't set the ref. | ||
# This can happen for primitive types that don't have __dict__ | ||
pass | ||
|
There was a problem hiding this comment.
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