From fe4dc839dde6bee6f0c0c6519581ba3c6e2d0ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 28 Oct 2024 16:24:11 +0100 Subject: [PATCH] Handle foreign key violation with savepoint Apparently wrapping a potential database error in an eval doesn't prevent DBIx::Class from aborting the transaction. But with a SAVEPOINT we can wiork around that. svp_rollback will set back the transaction to the sate from svp_begin. Issue: https://progress.opensuse.org/issues/124487 --- lib/OpenQA/Shared/Plugin/Gru.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/OpenQA/Shared/Plugin/Gru.pm b/lib/OpenQA/Shared/Plugin/Gru.pm index 2c47963b323..3867603456a 100644 --- a/lib/OpenQA/Shared/Plugin/Gru.pm +++ b/lib/OpenQA/Shared/Plugin/Gru.pm @@ -144,6 +144,7 @@ sub _find_existing_minion_job ($self, $task, $args, $job_ids) { sub _add_jobs_to_gru_task ($self, $gru_id, $job_ids) { my $schema = OpenQA::Schema->singleton; + $schema->svp_begin('try_gru_dependencies'); for my $id (@$job_ids) { # Add job to existing gru task with the same args my $gru_dep = eval { $schema->resultset('GruDependencies')->create({job_id => $id, gru_task_id => $gru_id}); }; @@ -155,9 +156,11 @@ sub _add_jobs_to_gru_task ($self, $gru_id, $job_ids) { # if the GruTask was already deleted meanwhile, we can skip # the rest of the jobs, since the wanted task was done log_debug("GruTask $gru_id already gone, skip assigning jobs (message: $error)"); + $schema->svp_rollback('try_gru_dependencies'); last; } } + $schema->svp_release('try_gru_dependencies'); } sub enqueue ($self, $task, $args = [], $options = {}, $jobs = []) {