`gitlab/v1/repositories/<path>/?size=self_with_descendants` API throwing a 404 error when the root repo does not exist
Problem
This was noticed by @10io in a local test.
If doing GET /gitlab/v1/repositories/foo/bar/?size=self_with_descendants
, and foo/bar
does not exist on the metadata DB but foo/bar/car
(or any other sub repository under foo/bar
) do, the API is throwing a 404 Not Found
.
Upon checking the code, we can see that the query is handling non-existing base repositories correctly (here). However, before we get there, we're validating that the base repo (foo/bar
in this case) exists, in the API handler (here).
This was a side effect of #570 (closed). We used to automatically create repository records for any intermediate path segments, so repository records were guaranteed to exist for every portion of a path. This is no longer true.
Solution
Adapt the handler code so that it does not return a 404 Not Found
if the base repo does not exist but at least one sub-repo does. This should only be the behavior when the request is a get repository details and more precisely, the size
query param is present and set to self_with_descendats
.