Transferring project creates empty duplicate epics

Summary

This issue builds off of #362738, where epics are recreated in the destination group after a project is transferred.

In this case, additional duplicate epics, with no issues associated, are created for each associated issue that is transferred beyond the first.

I was able to reproduce this thanks to a customer's instructions in a support ticket (internal).

Steps to reproduce

  1. Create an epic in one group.
  2. Create a project in the same group.
  3. Create two issues in that project, and add them both to the epic.
  4. Transfer the project to a different group.

At this point, you should see that the other group now has two epics with the same name as the first, but only one has the two issues (the other has zero).

Example Project

This is only visible to GitLab team members, but you can see this behavior in the following link:

Example transfer destination group epics list

What is the current bug behavior?

Duplicate epics are created in the destination group.

What is the expected correct behavior?

Only one version of each epic should exist in the destination group after a project is transferred to it.

Relevant logs and/or screenshots

Please see the following graph representing the before and after states of this bug behavior:

flowchart LR
    subgraph Before
        A1[Top-level group] --> B1[Source group]
        A1[Top-level group] --> C1[Destination group]
        B1 --> D1[/"Epic I (&1)"/]
        B1 --> E1(Project A)
        E1 --> F1(["Issue 1 (#1)"])
        E1 --> G1(["Issue 2 (#2)"])
        E1 --> H1(["Issue 3 (#3)"])
        D1 -..- F1 & G1 & H1
    end
    subgraph After
        A[Top-level group] --> B[Source group]
        A[Top-level group] --> C[Destination group]
        B --> D[/"Epic I (&1)"/]
        C --> D2[/"Epic I (&1)"/]
        C --> D3[/"Epic I (&2)"/]
        C --> D4[/"Epic I (&3)"/]
        C --> E(Project A)
        E --> F(["Issue 1 (#1)"])
        E --> G(["Issue 2 (#2)"])
        E --> H(["Issue 3 (#3)"])
        D2 -..- F & G & H
    end
    Before -->|Project A transfered to Destination group| After

Output of checks

This bug happens on GitLab.com.

Possible fixes

Unknown at this time.

Edited by Andrew Conrad