Skip to content

Bitbucket Server Importer - Duplicate record errors for same user_id

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Issue

There have been multiple ActiveRecord::RecordNotUnique errors coming from the Bitbucket Server importer when trying to import approvals, merge_request_metrics, etc (kibana logs - internal):

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_approvals_on_user_id_and_merge_request_id"

The changes in !198010 (merged) to map user contributions to a personal namespace user will make these errors more common. These errors should be addressed before the feature flag to map to a personal namespace user, user_mapping_to_personal_namespace_owner, is rolled out.

Identified in !198010 (comment 2642472304)

Proposed solution

Approvals: Check if an approval is valid before attempting to persist it in GitLab::Import::MergeRequestHelpers. Even though create is used instead of create!, ActiveRecord::RecordNotUnique is still raised because of the postgres constraint.

Merge request metrics: Similar to approvals, check if the metric is valid before updating because ActiveRecord::RecordNotUnique can be raised by update even though there's no !

Identify other records imported from Bitbucket Server that could fail when its user is not unique and apply a similar approach

Edited by 🤖 GitLab Bot 🤖