Skip to content

Commit

Permalink
fix(api): prevent moving a labware onto itself (#16600)
Browse files Browse the repository at this point in the history
Fixes bug where you could move a labware onto itself, causing a recursion error later in the protocol
  • Loading branch information
jbleon95 authored Oct 24, 2024
1 parent d907591 commit df01e77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/src/opentrons/protocol_engine/commands/move_labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ async def execute(self, params: MoveLabwareParams) -> _ExecuteReturn: # noqa: C
top_labware_definition=current_labware_definition,
bottom_labware_id=available_new_location.labwareId,
)
if params.labwareId == available_new_location.labwareId:
raise LabwareMovementNotAllowedError(
"Cannot move a labware onto itself."
)

# Allow propagation of ModuleNotLoadedError.
new_offset_id = self._equipment.find_applicable_labware_offset_id(
Expand Down
35 changes: 35 additions & 0 deletions api/tests/opentrons/protocol_engine/commands/test_move_labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,38 @@ async def test_move_labware_raises_when_moving_fixed_trash_labware(
match="Cannot move fixed trash labware 'My cool labware'.",
):
await subject.execute(data)


async def test_labware_raises_when_moved_onto_itself(
decoy: Decoy,
subject: MoveLabwareImplementation,
state_view: StateView,
) -> None:
"""It should raise when the OnLabwareLocation has the same labware ID as the labware being moved."""
data = MoveLabwareParams(
labwareId="the-same-labware-id",
newLocation=OnLabwareLocation(labwareId="a-cool-labware-id"),
strategy=LabwareMovementStrategy.MANUAL_MOVE_WITH_PAUSE,
)

decoy.when(state_view.labware.get(labware_id="the-same-labware-id")).then_return(
LoadedLabware(
id="the-same-labware-id",
loadName="load-name",
definitionUri="opentrons-test/load-name/1",
location=DeckSlotLocation(slotName=DeckSlotName.SLOT_4),
offsetId=None,
)
)

decoy.when(
state_view.geometry.ensure_location_not_occupied(
location=OnLabwareLocation(labwareId="a-cool-labware-id"),
)
).then_return(OnLabwareLocation(labwareId="the-same-labware-id"))

with pytest.raises(
errors.LabwareMovementNotAllowedError,
match="Cannot move a labware onto itself.",
):
await subject.execute(data)

0 comments on commit df01e77

Please sign in to comment.