Commit 0f030f83 authored by Yorick Peterse's avatar Yorick Peterse

Fix cross database transaction when blocking users

When blocking a user, CI related queries are executed after the user's
state transitions to the "blocked" state. This commit ensures those
queries don't run in the same transaction as is used to update the user.

This fixes https://gitlab.com/gitlab-org/gitlab/-/issues/346235

Changelog: fixed
parent d6e94fa6
......@@ -391,8 +391,10 @@ class User < ApplicationRecord
# this state transition object in order to do a rollback.
# For this reason the tradeoff is to disable this cop.
after_transition any => :blocked do |user|
Ci::DropPipelineService.new.execute_async_for_all(user.pipelines, :user_blocked, user)
Ci::DisableUserPipelineSchedulesService.new.execute(user)
user.run_after_commit do
Ci::DropPipelineService.new.execute_async_for_all(user.pipelines, :user_blocked, user)
Ci::DisableUserPipelineSchedulesService.new.execute(user)
end
end
after_transition any => :deactivated do |user|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment