33from importlib .metadata import entry_points
44from typing import Any
55
6- import ispyb .sqlalchemy ._auto_db_schema as ISPyBDB
76from sqlmodel import Session as SQLModelSession , select
87
98import murfey .util .db as MurfeyDB
@@ -202,15 +201,28 @@ def _register_milling_step(
202201 if site_info .stage_info is None :
203202 logger .error ("No stage info found in current message" )
204203 return None
204+ # Check that GridSquare has ID (for type checking)
205+ if grid_square .id is None :
206+ logger .error ("Current GridSquare entry has no ID" )
207+ return None
205208
206209 # Iteratively go through the LamellaSiteInfo model and insert for each step
207210 for steps , stage_name in MILLING_STEP_LOOKUP :
208- for step_name , step_id in steps :
211+ for step_name , _ in steps :
209212 step_info : MillingStepInfo | None = site_info .steps .__getattribute__ (
210213 step_name
211214 )
215+ # Early continues if key information is missing
212216 if step_info is None :
217+ logger .debug (f"No step info found for { step_name } " )
218+ continue
219+ if step_info .recipe_name is None :
220+ logger .debug (f"No recipe name found for { step_name } " )
213221 continue
222+ if step_info .step_name is None :
223+ logger .debug (f"No step name found for { step_name } " )
224+ continue
225+
214226 stage_values : StagePositionValues | None = (
215227 site_info .stage_info .__getattribute__ (stage_name )
216228 )
@@ -227,33 +239,33 @@ def _register_milling_step(
227239
228240 if milling_step_entry is None :
229241 # Create a new ISPyB entry if no Murfey one is found
230- record = ISPyBDB . MillingStep (
242+ result = _transport_object . do_insert_milling_step (
231243 # IDs
232- millingStepNameId = step_id ,
233- gridSquareId = grid_square .id ,
244+ recipe_name = step_info .recipe_name ,
245+ activity_name = step_info .step_name ,
246+ grid_square_id = grid_square .id ,
234247 # Values
235- isEnabled = step_info .is_enabled ,
248+ is_enabled = step_info .is_enabled ,
236249 status = step_info .status ,
237- executionTime = step_info .execution_time ,
238- stageX = stage_values .x ,
239- stageY = stage_values .y ,
240- stageZ = stage_values .z ,
250+ execution_time = step_info .execution_time ,
251+ stage_x = stage_values .x ,
252+ stage_y = stage_values .y ,
253+ stage_z = stage_values .z ,
241254 rotation = stage_values .rotation ,
242- alphaTilt = stage_values .tilt_alpha ,
243- beamType = step_info .beam_type ,
244- beamVoltage = step_info .voltage ,
245- beamCurrent = step_info .current ,
246- millingAngle = step_info .milling_angle ,
247- depthCorrection = step_info .depth_correction ,
248- lamellaOffset = step_info .lamella_offset ,
249- trenchHeightFront = step_info .trench_height_front ,
250- trenchHeightRear = step_info .trench_height_rear ,
251- widthOverlapFrontLeft = step_info .width_overlap_front_left ,
252- widthOverlapFrontRight = step_info .width_overlap_front_right ,
253- widthOverlapRearLeft = step_info .width_overlap_rear_left ,
254- widthOverlapRearRight = step_info .width_overlap_rear_right ,
255+ tilt_alpha = stage_values .tilt_alpha ,
256+ beam_type = step_info .beam_type ,
257+ beam_voltage = step_info .voltage ,
258+ beam_current = step_info .current ,
259+ milling_angle = step_info .milling_angle ,
260+ depth_correction = step_info .depth_correction ,
261+ lamella_offset = step_info .lamella_offset ,
262+ trench_height_front = step_info .trench_height_front ,
263+ trench_height_rear = step_info .trench_height_rear ,
264+ width_overlap_front_left = step_info .width_overlap_front_left ,
265+ width_overlap_front_right = step_info .width_overlap_front_right ,
266+ width_overlap_rear_left = step_info .width_overlap_rear_left ,
267+ width_overlap_rear_right = step_info .width_overlap_rear_right ,
255268 )
256- result = _transport_object .do_insert_milling_step (record )
257269 if result .get ("return_value" ) is None :
258270 logger .error (
259271 f"No MillingStep entry created for { step_info .step_name } "
0 commit comments