Skip to content

Commit 76f7136

Browse files
committed
Need to ensure hole is present before returning it
1 parent 6ec3105 commit 76f7136

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/murfey/workflows/spa/flush_spa_preprocess.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def register_foil_hole(
110110
gs_name: int,
111111
foil_hole_params: FoilHoleParameters,
112112
murfey_db: Session,
113-
):
113+
) -> bool:
114114
try:
115115
gs = murfey_db.exec(
116116
select(GridSquare)
@@ -120,10 +120,10 @@ def register_foil_hole(
120120
).one()
121121
gsid = gs.id
122122
except NoResultFound:
123-
logger.debug(
123+
logger.warning(
124124
f"Foil hole {sanitise(str(foil_hole_params.name))} could not be registered as grid square {sanitise(str(gs_name))} was not found"
125125
)
126-
return
126+
return False
127127
secured_foil_hole_image_path = secure_filename(foil_hole_params.image)
128128
if foil_hole_params.image and Path(secured_foil_hole_image_path).is_file():
129129
jpeg_size = Image.open(secured_foil_hole_image_path).size
@@ -193,6 +193,7 @@ def register_foil_hole(
193193
murfey_db.add(foil_hole)
194194
murfey_db.commit()
195195
murfey_db.close()
196+
return True
196197

197198

198199
def _grid_square_metadata_file(f: Path, grid_square: int) -> Optional[Path]:
@@ -287,8 +288,10 @@ def _flush_position_analysis(
287288
name=foil_hole,
288289
)
289290
# Insert or update this foil hole in the database
290-
register_foil_hole(session_id, gs.id, foil_hole_parameters, murfey_db)
291-
return foil_hole
291+
registered_hole = register_foil_hole(
292+
session_id, gs.id, foil_hole_parameters, murfey_db
293+
)
294+
return foil_hole if registered_hole else None
292295

293296

294297
def flush_spa_preprocess(message: dict, murfey_db: Session, demo: bool = False) -> bool:

0 commit comments

Comments
 (0)