Skip to content

Commit 83cbe75

Browse files
committed
fix: change db.commit() to db.flush() for better transaction handling and clarify error logging for variant updates
1 parent 085177c commit 83cbe75

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/mavedb/worker/jobs.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async def create_variants_for_score_set(
196196

197197
logger.info(msg="Deleted existing variants from score set.", extra=logging_context)
198198

199-
db.commit()
199+
db.flush()
200200
db.refresh(score_set)
201201

202202
variants_data = create_variants_data(validated_scores, validated_counts, None)
@@ -210,6 +210,11 @@ async def create_variants_for_score_set(
210210
score_set.processing_errors = {"exception": str(e), "detail": e.triggering_exceptions}
211211
score_set.mapping_state = MappingState.not_attempted
212212

213+
if score_set.num_variants:
214+
score_set.processing_errors["exception"] = (
215+
f"Update failed, variants were not updated. {score_set.processing_errors.get('exception', '')}"
216+
)
217+
213218
logging_context = {**logging_context, **format_raised_exception_info_as_dict(e)}
214219
logging_context["processing_state"] = score_set.processing_state.name
215220
logging_context["mapping_state"] = score_set.mapping_state.name
@@ -226,6 +231,11 @@ async def create_variants_for_score_set(
226231
score_set.processing_errors = {"exception": str(e), "detail": []}
227232
score_set.mapping_state = MappingState.not_attempted
228233

234+
if score_set.num_variants:
235+
score_set.processing_errors["exception"] = (
236+
f"Update failed, variants were not updated. {score_set.processing_errors.get('exception', '')}"
237+
)
238+
229239
logging_context = {**logging_context, **format_raised_exception_info_as_dict(e)}
230240
logging_context["processing_state"] = score_set.processing_state.name
231241
logging_context["mapping_state"] = score_set.mapping_state.name
@@ -1296,9 +1306,9 @@ async def link_clingen_variants(ctx: dict, correlation_id: str, score_set_id: in
12961306
logging_context["linkage_failures"] = num_linkage_failures
12971307
logging_context["linkage_successes"] = num_variant_urns - num_linkage_failures
12981308

1299-
assert len(linked_allele_ids) == num_variant_urns, (
1300-
f"{num_variant_urns - len(linked_allele_ids)} appear to not have been attempted to be linked."
1301-
)
1309+
assert (
1310+
len(linked_allele_ids) == num_variant_urns
1311+
), f"{num_variant_urns - len(linked_allele_ids)} appear to not have been attempted to be linked."
13021312

13031313
job_succeeded = False
13041314
if not linkage_failures:

0 commit comments

Comments
 (0)