Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): prevent moving a labware onto itself #16600

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's the error! :shipit:

)

# Allow propagation of ModuleNotLoadedError.
new_offset_id = self._equipment.find_applicable_labware_offset_id(
Expand Down
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)
Loading