Epics being created with duplicate `iid`s

Summary

See https://gitlab.slack.com/archives/CETG54GQ0/p1604623964331700

Creating an epic sometimes results in the reuse of an existing iid. This causes unexpected behavior, such as one of the epics being visible in links and tooltips but unavailable due to a URL collision with the other.

Steps to reproduce

Example Project

This issue has an epic called Supported Kubernetes Versions. When clicked, it links instead to Improve Test Efficiency because there's an iid collision.

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com

Possible fixes

  • In a transaction:
    • Iterate over duplicates and assign a new iid to each
    • Add a unique index (something like CREATE UNIQUE INDEX index_epics_on_group_id_and_iid ON epics USING btree (group_id, iid);
Edited by Alexandru Croitor