Remove invalid parents from the Commit object
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 |
---|---|
How to set up and validate locally
You can patch the code to emulate this problem.
- Open app/models/commit.rb
- 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
- Visit any commit page (http://gdk.test:3000/gitlab-org/gitlab-test/-/commit/c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd)
- It should load without any errors (parents list will be empty)
Edited by Vasilii Iakliushin