Fix errors when deleting a forked project
The problem would occur when the `ForkedProjectLink` was deleted, but the `ForkNetworkMember` was not. The delete would be rolled back and retried. But the error would not be saved because `Project#forked?` would still be true, because the `ForkNetworkMember` exists. But the `Project#forked_project_link` would be `nil`. So the validation for the visibility level would fail.
This commit is contained in:
parent
f69b54682f
commit
2c0b677604
|
@ -1272,7 +1272,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
# self.forked_from_project will be nil before the project is saved, so
|
||||
# we need to go through the relation
|
||||
original_project = forked_project_link.forked_from_project
|
||||
original_project = forked_project_link&.forked_from_project
|
||||
return true unless original_project
|
||||
|
||||
level <= original_project.visibility_level
|
||||
|
|
|
@ -15,8 +15,8 @@ module Projects
|
|||
|
||||
refresh_forks_count(@project.forked_from_project)
|
||||
|
||||
@project.forked_project_link.destroy
|
||||
@project.fork_network_member.destroy
|
||||
@project.forked_project_link.destroy
|
||||
end
|
||||
|
||||
def refresh_forks_count(project)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix error when updating a forked project with deleted `ForkedProjectLink`
|
||||
merge_request: 14916
|
||||
author:
|
||||
type: fixed
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Projects::DestroyService do
|
||||
include ProjectForksHelper
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
let!(:project) { create(:project, :repository, namespace: user.namespace) }
|
||||
let!(:path) { project.repository.path_to_repo }
|
||||
|
@ -212,6 +214,21 @@ describe Projects::DestroyService do
|
|||
end
|
||||
end
|
||||
|
||||
context 'for a forked project with LFS objects' do
|
||||
let(:forked_project) { fork_project(project, user) }
|
||||
|
||||
before do
|
||||
project.lfs_objects << create(:lfs_object)
|
||||
forked_project.forked_project_link.destroy
|
||||
forked_project.reload
|
||||
end
|
||||
|
||||
it 'destroys the fork' do
|
||||
expect { destroy_project(forked_project, user) }
|
||||
.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'as the root of a fork network' do
|
||||
let!(:fork_network) { create(:fork_network, root_project: project) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue