Skip to content

Create project_feature in after_create_commit instead of after_create

What does this MR do?

This MR changes project_feature creation callback from after_create to after_create_commit. There is a project import request that fails due to the following error:

PG::ForeignKeyViolation: ERROR: insert or update on table "project_features" violates foreign key constraint "fk_18513d9b92" DETAIL: Key (project_id)=(14359728) is not present in table "projects". : INSERT INTO "project_features" ("project_id", "created_at", "updated_at", "builds_access_level", "issues_access_level", "merge_requests_access_level", "snippets_access_level", "wiki_access_level", "repository_access_level", "pages_access_level") VALUES (14359728, '2019-09-17 20:31:45.123822', '2019-09-17 20:31:45.123822', 20, 20, 20, 20, 20, 20, 10) RETURNING "id"

After analysing production log from https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/7904#note_222273184 I noticed one thing we do during project saving (which is wrapped in a transaction) is upload user's upload to Google Storage. It is better to use after_create_commit callback in this case as per https://guides.rubyonrails.org/active_record_callbacks.html#transaction-callbacks

Please see https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/7904#note_222560231 (internal) for more details.

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports