Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/2696.
EE version: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2182