Commit 2c0b6776 authored by Bob Van Landuyt's avatar Bob Van Landuyt

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.
parent f69b5468
...@@ -1272,7 +1272,7 @@ class Project < ActiveRecord::Base ...@@ -1272,7 +1272,7 @@ class Project < ActiveRecord::Base
# self.forked_from_project will be nil before the project is saved, so # self.forked_from_project will be nil before the project is saved, so
# we need to go through the relation # 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 return true unless original_project
level <= original_project.visibility_level level <= original_project.visibility_level
......
...@@ -15,8 +15,8 @@ module Projects ...@@ -15,8 +15,8 @@ module Projects
refresh_forks_count(@project.forked_from_project) refresh_forks_count(@project.forked_from_project)
@project.forked_project_link.destroy
@project.fork_network_member.destroy @project.fork_network_member.destroy
@project.forked_project_link.destroy
end end
def refresh_forks_count(project) def refresh_forks_count(project)
......
---
title: Fix error when updating a forked project with deleted `ForkedProjectLink`
merge_request: 14916
author:
type: fixed
require 'spec_helper' require 'spec_helper'
describe Projects::DestroyService do describe Projects::DestroyService do
include ProjectForksHelper
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: user.namespace) } let!(:project) { create(:project, :repository, namespace: user.namespace) }
let!(:path) { project.repository.path_to_repo } let!(:path) { project.repository.path_to_repo }
...@@ -212,6 +214,21 @@ describe Projects::DestroyService do ...@@ -212,6 +214,21 @@ describe Projects::DestroyService do
end end
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 context 'as the root of a fork network' do
let!(:fork_network) { create(:fork_network, root_project: project) } let!(:fork_network) { create(:fork_network, root_project: project) }
......
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