Fix #root_ancestor when parent_id is defined

What does this MR do and why?

This solves the issue where API requests to create a group with a parent_id and default_branch_protection_defaults parameter results in a 500 internal service error.

I've corrected the primary issue which is an edge case handling of #root_ancestor. I have also added a spec to the API endpoint to protect against regressions of the originating issue.

Query Plan

There is a new query for when a Namespace is initialized with only a parent_id and we want it's #root_ancestor. We optimize this case to perform a single query rather than loading the parent and then calling parent.root_ancestor to make a second query.

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/32312/commands/99824

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.

Closes #497493 (closed)

Edited by Alex Pooley

Merge request reports

Loading