Skip to content

Commit

Permalink
Fix incorrect construction of LabwareOffsetVectors.
Browse files Browse the repository at this point in the history
The old code was type-unsafe (`cast()`) but we got away with it because both types had compatible fields. Earlier commits in this PR tried to fix that by using `model_validate()` instead of `cast()`. But `model_validate()` can't directly convert one Pydantic model into another like that, so it raised a runtime error. That wasn't caught by the type checker because `model_validate()` is, sensibly, typed to allow any untrusted input.

This converts between the two types verbosely and type-safely, by spelling out each field.
  • Loading branch information
SyntaxColoring committed Dec 13, 2024
1 parent ab27980 commit 944b3f5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions api/src/opentrons/protocol_engine/state/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,11 +998,15 @@ def get_child_gripper_offsets(
return None
else:
return LabwareMovementOffsetData(
pickUpOffset=LabwareOffsetVector.model_validate(
parsed_offsets[offset_key].pickUpOffset
pickUpOffset=LabwareOffsetVector.model_construct(
x=parsed_offsets[offset_key].pickUpOffset.x,
y=parsed_offsets[offset_key].pickUpOffset.y,
z=parsed_offsets[offset_key].pickUpOffset.z,
),
dropOffset=LabwareOffsetVector.model_validate(
parsed_offsets[offset_key].dropOffset
dropOffset=LabwareOffsetVector.model_construct(
x=parsed_offsets[offset_key].dropOffset.x,
y=parsed_offsets[offset_key].dropOffset.y,
z=parsed_offsets[offset_key].dropOffset.z,
),
)

Expand Down

0 comments on commit 944b3f5

Please sign in to comment.