Skip to content

Commit

Permalink
do not perform_io_checks when reevaluating on field assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Oct 28, 2024
1 parent 7e6a274 commit c40ec33
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions bioimageio/spec/model/v0_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .._internal.types import LicenseId as LicenseId
from .._internal.types import NotEmpty as NotEmpty
from .._internal.url import HttpUrl as HttpUrl
from .._internal.validation_context import validation_context_var
from .._internal.validator_annotations import AfterValidator, RestrictCharacters
from .._internal.version_type import Version as Version
from .._internal.warning_levels import ALERT, INFO
Expand Down Expand Up @@ -875,7 +876,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 +892,11 @@ 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)
# create WeightsDescr with single weight format entry
with validation_context_var.get().replace(perform_io_checks=False):
new_w = w.model_copy()
new_w.parent = None
value = value.__class__(**{wf: new_w})

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

0 comments on commit c40ec33

Please sign in to comment.