Create project feature in after_create_commit
There is an issue with project import that fails with error on GitLab.com
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"
due to the fact that project import is wrapped into a transaction, and inside that transaction there is upload creation, which calls Google Storage. After it's done project feature creation fails.
Replace after_create
with after_create_commit
as it is especially useful in these kind of situations (see https://guides.rubyonrails.org/active_record_callbacks.html#transaction-callbacks)
More details in https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/7904 (internal)
https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/7904#note_222560231