Skip to content
Snippets Groups Projects

Fix 500 error in Commits API when the repository is empty

Merged Vasilii Iakliushin requested to merge 452488_fix_empty_repository_case_in_commits_api into master
1 unresolved thread

What does this MR do and why?

Contributes to #452488 (closed)

Problem

Gitaly started returning an internal error, when the user requests commits of the empty repository: gitaly!6590 (merged). Rails doesn't handle it and returns a 500 error.

Solution

Add a temporary handler for this error, before the Gitaly code is updated.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Create a project with an empty repository (without README.md)
  2. Visit http://127.0.0.1:3000/api/v4/projects/<project_id>/repository/commits
  3. You should see an empty array response instead of an internal error.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
171 171 commits = Commit.decorate(commits, container) if commits.present?
172 172
173 173 CommitCollection.new(container, commits, ref)
174 rescue Gitlab::Git::CommandError => e
175 # Temporary fix to address a new Gitaly internal error: https://gitlab.com/gitlab-org/gitlab/-/issues/452488
176 return CommitCollection.new(container, [], ref) if e.message.include?('listing commits failed')
  • added workflowstaging label and removed workflowcanary label

  • mentioned in merge request !148979 (merged)

  • Please register or sign in to reply
    Loading