Skip to content

Commit

Permalink
Handle foreign key violation with savepoint
Browse files Browse the repository at this point in the history
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
  • Loading branch information
perlpunk committed Oct 28, 2024
1 parent e85916c commit fe4dc83
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/OpenQA/Shared/Plugin/Gru.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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}); };
Expand All @@ -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 = []) {
Expand Down

0 comments on commit fe4dc83

Please sign in to comment.