Skip to content

Fix Import/Export protected branch access levels associated with user

What does this MR do and why?

This MR fixes an issue with Project Import/Export of protected branches that have user (or group) associated with them. Prior to this fix a protected branch that had merge or push access levels associated with users would fail to be imported due to the following exception:

ProtectedBranch::MergeAccessLevel#project delegated to protected_branch.project, but protected_branch is nil: #<ProtectedBranch::MergeAccessLevel id: nil, protected_branch_id: nil, access_level: 40, created_at: \"2022-11-24 03:27:59.574000000 +0000\"

The exception is raised due to a call to protected_refs_for_users_required_and_available callback which calls project that is delegated to protected_branch, but protected_branch is nil during the run of these validations (since we do not have a valid protected branch just yet).

The 'fix', which is more of a workaround, is to not run these callbacks, which is a common practice for Import/Export in order to get the records migrated. As I mentioned above, this callback is skipped because we don't have access to protected_branch or project when validations are ran against merge_access_levels & push_access_levels. So let's create them blindly, instead of completely failing.

Mentions #387014 (closed)

Screenshots or screen recordings

before after
prot-before.mov prot-after.mov

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports