Skip to content

Commit

Permalink
Add update option for tomogram table
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riggs committed Sep 4, 2024
1 parent 92d4ecc commit 662468d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cryoemservices/services/ispyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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:
Expand Down

0 comments on commit 662468d

Please sign in to comment.