6
6
from opentrons .protocol_engine .types import (
7
7
LabwareOffsetVector ,
8
8
ModuleModel ,
9
- OnAddressableAreaOffsetSequenceComponent ,
10
- OnModuleOffsetSequenceComponent ,
11
- OnLabwareOffsetSequenceComponent ,
9
+ OnAddressableAreaOffsetLocationSequenceComponent ,
10
+ OnModuleOffsetLocationSequenceComponent ,
11
+ OnLabwareOffsetLocationSequenceComponent ,
12
12
LabwareOffsetLocationSequenceComponents ,
13
13
)
14
14
from opentrons .types import DeckSlotName
@@ -42,8 +42,6 @@ class _DoNotFilter(enum.Enum):
42
42
"""
43
43
44
44
45
- # todo(mm, 2024-12-06): Convert to be SQL-based and persistent instead of in-memory.
46
- # https://opentrons.atlassian.net/browse/EXEC-1015
47
45
class LabwareOffsetStore :
48
46
"""A persistent store for labware offsets, to support the `/labwareOffsets` endpoints."""
49
47
@@ -69,7 +67,9 @@ def add(self, offset: StoredLabwareOffset) -> None:
69
67
.row_id
70
68
)
71
69
transaction .execute (
72
- sqlalchemy .insert (labware_offset_table ).values (
70
+ sqlalchemy .insert (
71
+ labware_offset_location_sequence_components_table
72
+ ).values (
73
73
list (
74
74
_pydantic_to_sql_location_sequence_iterator (
75
75
offset , offset_row_id
@@ -98,7 +98,7 @@ def search(
98
98
.join (
99
99
labware_offset_location_sequence_components_table ,
100
100
labware_offset_table .c .row_id
101
- == labware_offset_sequence_table .c .offset_id ,
101
+ == labware_offset_location_sequence_components_table .c .offset_id ,
102
102
)
103
103
.where (labware_offset_table .c .active == True ) # noqa: E712
104
104
)
@@ -112,7 +112,7 @@ def search(
112
112
labware_offset_table .c .definition_uri == definition_uri_filter
113
113
)
114
114
if location_slot_name_filter is not DO_NOT_FILTER :
115
- filter_statement = (
115
+ filter_statement = filter_statement . where (
116
116
filter_statement .where (
117
117
labware_offset_location_sequence_components_table .c .component_kind
118
118
== "onAddressableArea"
@@ -121,15 +121,15 @@ def search(
121
121
labware_offset_location_sequence_components_table .c .primary_component_value
122
122
== location_slot_name_filter .value
123
123
)
124
- .exists (0 )
124
+ .exists ()
125
125
)
126
126
if location_module_model_filter is not DO_NOT_FILTER :
127
127
location_module_model_filter_value = (
128
128
location_module_model_filter .value
129
129
if location_module_model_filter is not None
130
130
else None
131
131
)
132
- filter_statement = (
132
+ filter_statement = filter_statement . where (
133
133
filter_statement .where (
134
134
labware_offset_location_sequence_components_table .c .component_kind
135
135
== "onModule"
@@ -141,7 +141,7 @@ def search(
141
141
.exists ()
142
142
)
143
143
if location_definition_uri_filter is not DO_NOT_FILTER :
144
- filter_statement = (
144
+ filter_statement = filter_statement . where (
145
145
filter_statement .where (
146
146
labware_offset_location_sequence_components_table .c .component_kind
147
147
== "onLabware"
@@ -217,15 +217,15 @@ def _sql_sequence_component_to_pydantic_sequence_component(
217
217
component_row : sqlalchemy .engine .Row ,
218
218
) -> LabwareOffsetLocationSequenceComponents :
219
219
if component_row .component_kind == "onLabware" :
220
- yield OnLabwareOffsetSequenceComponent (
220
+ yield OnLabwareOffsetLocationSequenceComponent (
221
221
labwareUri = component_row .primary_component_value
222
222
)
223
223
elif component_row .component_kind == "onModule" :
224
- yield OnModuleOffsetSequenceComponent (
224
+ yield OnModuleOffsetLocationSequenceComponent (
225
225
moduleModel = ModuleModel (component_row .primary_component_value )
226
226
)
227
227
elif component_row .component_kind == "onAddressableArea" :
228
- yield OnAddressableAreaOffsetSequenceComponent (
228
+ yield OnAddressableAreaOffsetLocationSequenceComponent (
229
229
addressableAreaName = component_row .primary_component_value
230
230
)
231
231
else :
@@ -297,23 +297,23 @@ def _pydantic_to_sql_location_sequence_iterator(
297
297
labware_offset : StoredLabwareOffset , offset_row_id : int
298
298
) -> Iterator [dict [str , object ]]:
299
299
for index , component in labware_offset .locationSequence :
300
- if isinstance (component , OnLabwareOffsetSequenceComponent ):
300
+ if isinstance (component , OnLabwareOffsetLocationSequenceComponent ):
301
301
yield dict (
302
302
offset_id = offset_row_id ,
303
303
sequence_ordinal = index ,
304
304
component_kind = component .kind ,
305
305
primary_component_value = component .labwareUri ,
306
306
component_value_json = component .model_dump (),
307
307
)
308
- elif isinstance (component , OnModuleOffsetSequenceComponent ):
308
+ elif isinstance (component , OnModuleOffsetLocationSequenceComponent ):
309
309
yield dict (
310
310
offset_id = offset_row_id ,
311
311
sequence_ordinal = index ,
312
312
component_kind = component .kind ,
313
313
primary_component_value = component .moduleModel .value ,
314
314
component_value_json = component .model_dump (),
315
315
)
316
- elif isinstance (component , OnAddressableAreaOffsetSequenceComponent ):
316
+ elif isinstance (component , OnAddressableAreaOffsetLocationSequenceComponent ):
317
317
yield dict (
318
318
offset_id = offset_row_id ,
319
319
sequence_ordinal = index ,
0 commit comments