From 662468de9b09ead72d4bbbcd2d420e192dd1b51f Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Wed, 4 Sep 2024 08:56:42 +0100 Subject: [PATCH] Add update option for tomogram table --- src/cryoemservices/services/ispyb.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cryoemservices/services/ispyb.py b/src/cryoemservices/services/ispyb.py index f25aa972..4307847e 100644 --- a/src/cryoemservices/services/ispyb.py +++ b/src/cryoemservices/services/ispyb.py @@ -964,6 +964,7 @@ def full_parameters(param): try: values = models.Tomogram( + tomogramId=full_parameters("tomogram_id"), dataCollectionId=full_parameters("dcid"), autoProcProgramId=full_parameters("program_id"), volumeFile=full_parameters("volume_file"), @@ -985,7 +986,26 @@ def full_parameters(param): projXZ=full_parameters("proj_xz"), globalAlignmentQuality=full_parameters("alignment_quality"), ) - session.add(values) + tomogram_row = ( + session.query(models.Tomogram) + .filter( + models.Tomogram.tomogramId == values.tomogramId, + ) + .first() + ) + if tomogram_row: + session.query(models.Tomogram).filter( + models.Tomogram.tomogramId == values.tomogramId, + ).update( + { + k: v + for k, v in values.__dict__.items() + if k not in ["_sa_instance_state", "tomogramId"] + and v is not None + } + ) + else: + session.add(values) session.commit() return {"success": True, "return_value": values.tomogramId} except sqlalchemy.exc.SQLAlchemyError as e: