Skip to content

Commit

Permalink
Merge pull request #646 from bioimage-io/fix638
Browse files Browse the repository at this point in the history
Fix 638
  • Loading branch information
FynnBe authored Oct 29, 2024
2 parents 7e6a274 + ef9d875 commit a20e58b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions bioimageio/spec/model/v0_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ class LinkedModel(Node):


def package_weights(
value: Node,
value: Node, # Union[v0_4.WeightsDescr, v0_5.WeightsDescr]
handler: SerializerFunctionWrapHandler,
info: SerializationInfo,
):
Expand All @@ -891,14 +891,10 @@ def package_weights(
+ f" ({ctxt.weights_priority_order}) is present in the given model."
)

# remove links to parent entry (otherwise we cannot remove the parent)
for _, w in value:
if w is not None:
w.parent = None

for field_name in value.model_fields:
if field_name != wf:
setattr(value, field_name, None)
assert isinstance(w, Node), type(w)
# construct WeightsDescr with new single weight format entry
new_w = w.model_construct(**{k: v for k, v in w if k != "parent"})
value = value.model_construct(None, **{wf: new_w})

return handler(
value, info # pyright: ignore[reportArgumentType] # taken from pydantic docs
Expand Down

0 comments on commit a20e58b

Please sign in to comment.