Skip to content

Commit 944b3f5

Browse files
Fix incorrect construction of LabwareOffsetVectors.
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.
1 parent ab27980 commit 944b3f5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

api/src/opentrons/protocol_engine/state/labware.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,15 @@ def get_child_gripper_offsets(
998998
return None
999999
else:
10001000
return LabwareMovementOffsetData(
1001-
pickUpOffset=LabwareOffsetVector.model_validate(
1002-
parsed_offsets[offset_key].pickUpOffset
1001+
pickUpOffset=LabwareOffsetVector.model_construct(
1002+
x=parsed_offsets[offset_key].pickUpOffset.x,
1003+
y=parsed_offsets[offset_key].pickUpOffset.y,
1004+
z=parsed_offsets[offset_key].pickUpOffset.z,
10031005
),
1004-
dropOffset=LabwareOffsetVector.model_validate(
1005-
parsed_offsets[offset_key].dropOffset
1006+
dropOffset=LabwareOffsetVector.model_construct(
1007+
x=parsed_offsets[offset_key].dropOffset.x,
1008+
y=parsed_offsets[offset_key].dropOffset.y,
1009+
z=parsed_offsets[offset_key].dropOffset.z,
10061010
),
10071011
)
10081012

0 commit comments

Comments
 (0)