Sorting by name on explore projects page renders a 500 error when logged in

Summary

On the Explore Projects page, sorting by name returns a 500 error when you are logged in. When you are logged out, sorting by name works fine.

Steps to reproduce

What is the current bug behavior?

A 500 error page is shown

What is the expected correct behavior?

The explore projects page with all projects sorted by name should be shown

Relevant logs and/or screenshots

When running gitlab locally in development I get the following error about the generated SQL query:

ERROR:  column reference "name" is ambiguous at character 605
STATEMENT:
SELECT "projects"."id"
FROM   "projects"
       LEFT OUTER JOIN "routes"
                    ON "routes"."source_id" = "projects"."id"
                       AND "routes"."source_type" = $1
       LEFT OUTER JOIN "namespaces"
                    ON "namespaces"."id" = "projects"."namespace_id"
       LEFT OUTER JOIN "routes" "routes_namespaces"
                    ON "routes_namespaces"."source_id" = "namespaces"."id"
                       AND "routes_namespaces"."source_type" = $2
WHERE  ( EXISTS (SELECT 1
                 FROM   "project_authorizations"
                 WHERE  "project_authorizations"."user_id" = 1
                        AND ( project_authorizations.project_id = projects.id ))
          OR projects.visibility_level IN ( 0, 10, 20 ) )
       AND "projects"."archived" = $3
ORDER  BY Lower(name) ASC
LIMIT  20 offset 0 

Output of checks

This bug happens on GitLab.com

Possible fixes

the ORDER BY lower(name) should be prefixed with the projects table to ORDER BY lower(projects.name)

Edited by Aram Visser