Skip to content

Remove invalid parents from the Commit object

Vasilii Iakliushin requested to merge 478834_fix_commit_parents_loading into master

What does this MR do and why?

Contributes to #478834 (closed)

Problem

It is possible that commits might have pointers to non-existing parents. An attempt to display such commit will lead to NoMethodError.

Solution

Filter out invalid commit objects from parents list.

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
Screenshot_2024-08-14_at_10.37.53 Screenshot_2024-08-14_at_10.38.54

How to set up and validate locally

You can patch the code to emulate this problem.

  1. Open app/models/commit.rb
  2. Replace parent_ids array with an list of invalid commit shas. Like
   def parents
     # Usage of `reject` is intentional. `compact` doesn't work here, because of BatchLoader specifics
-    @parents ||= parent_ids.map { |oid| Commit.lazy(container, oid) }.reject(&:nil?)
+    @parents ||= ["111"].map { |oid| Commit.lazy(container, oid) }.reject(&:nil?)
   end
  1. Visit any commit page (http://gdk.test:3000/gitlab-org/gitlab-test/-/commit/c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd)
  2. It should load without any errors (parents list will be empty)
Edited by Vasilii Iakliushin

Merge request reports