@@ -53,13 +53,15 @@ def register_grid_square(
5353 if grid_square_params .width is not None :
5454 grid_square_params .width_scaled = int (grid_square_params .width / 7.8 )
5555
56- try :
57- grid_square = murfey_db .exec (
58- select (GridSquare )
59- .where (GridSquare .name == gsid )
60- .where (GridSquare .tag == grid_square_params .tag )
61- .where (GridSquare .session_id == session_id )
62- ).one ()
56+ grid_square_query = murfey_db .exec (
57+ select (GridSquare )
58+ .where (GridSquare .name == gsid )
59+ .where (GridSquare .tag == grid_square_params .tag )
60+ .where (GridSquare .session_id == session_id )
61+ ).all ()
62+ if grid_square_query :
63+ # Grid square already exists in the murfey database
64+ grid_square = grid_square_query [0 ]
6365 grid_square .x_location = grid_square_params .x_location or grid_square .x_location
6466 grid_square .y_location = grid_square_params .y_location or grid_square .y_location
6567 grid_square .x_stage_position = (
@@ -84,7 +86,8 @@ def register_grid_square(
8486 grid_square .image = grid_square_params .image or grid_square .image
8587 if _transport_object :
8688 _transport_object .do_update_grid_square (grid_square .id , grid_square_params )
87- except Exception :
89+ else :
90+ # No existing grid square in the murfey database
8891 if _transport_object :
8992 dcg = murfey_db .exec (
9093 select (DataCollectionGroup )
@@ -151,13 +154,15 @@ def register_foil_hole(
151154 jpeg_size = Image .open (secured_foil_hole_image_path ).size
152155 else :
153156 jpeg_size = (0 , 0 )
154- try :
155- foil_hole = murfey_db .exec (
156- select (FoilHole )
157- .where (FoilHole .name == foil_hole_params .name )
158- .where (FoilHole .grid_square_id == gsid )
159- .where (FoilHole .session_id == session_id )
160- ).one ()
157+ foil_hole_query = murfey_db .exec (
158+ select (FoilHole )
159+ .where (FoilHole .name == foil_hole_params .name )
160+ .where (FoilHole .grid_square_id == gsid )
161+ .where (FoilHole .session_id == session_id )
162+ ).one ()
163+ if foil_hole_query :
164+ # Foil hole already exists in the murfey database
165+ foil_hole = foil_hole_query [0 ]
161166 foil_hole .x_location = foil_hole_params .x_location or foil_hole .x_location
162167 foil_hole .y_location = foil_hole_params .y_location or foil_hole .y_location
163168 foil_hole .x_stage_position = (
@@ -183,7 +188,8 @@ def register_foil_hole(
183188 _transport_object .do_update_foil_hole (
184189 foil_hole .id , gs .thumbnail_size_x / gs .readout_area_x , foil_hole_params
185190 )
186- except Exception :
191+ else :
192+ # No existing foil hole in the murfey database
187193 if _transport_object :
188194 fh_ispyb_response = _transport_object .do_insert_foil_hole (
189195 gs .id ,
0 commit comments