Skip to content

Commit

Permalink
Implement HTTP delete by updating active to false instead of doing …
Browse files Browse the repository at this point in the history
…an actual SQL delete.
  • Loading branch information
SyntaxColoring committed Jan 10, 2025
1 parent 0cf8cac commit 358f3d4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions robot-server/robot_server/labware_offsets/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def search(
# making it worse.
) -> list[LabwareOffset]:
"""Return all matching labware offsets in order from oldest-added to newest."""
statement = sqlalchemy.select(labware_offset_table).order_by(
labware_offset_table.c.row_id
statement = (
sqlalchemy.select(labware_offset_table)
.order_by(labware_offset_table.c.row_id)
.where(labware_offset_table.c.active == True) # noqa: E712
)

if id_filter is not DO_NOT_FILTER:
Expand Down Expand Up @@ -119,19 +121,24 @@ def delete(self, offset_id: str) -> LabwareOffset:
).one()
except sqlalchemy.exc.NoResultFound:
raise LabwareOffsetNotFoundError(bad_offset_id=offset_id) from None
if not row_to_delete.active:
# Already soft-deleted.
raise LabwareOffsetNotFoundError(bad_offset_id=offset_id)

transaction.execute(
sqlalchemy.delete(labware_offset_table).where(
labware_offset_table.c.offset_id == offset_id
)
sqlalchemy.update(labware_offset_table)
.where(labware_offset_table.c.offset_id == offset_id)
.values(active=False)
)

return _sql_to_pydantic(row_to_delete)

def delete_all(self) -> None:
"""Delete all labware offsets."""
with self._sql_engine.begin() as transaction:
transaction.execute(sqlalchemy.delete(labware_offset_table))
transaction.execute(
sqlalchemy.update(labware_offset_table).values(active=False)
)


class LabwareOffsetNotFoundError(KeyError):
Expand Down

0 comments on commit 358f3d4

Please sign in to comment.