500 Error on any page with build status (Postgresql GROUP BY error)
Summary
I'm seeing a 500 error page when viewing any page that shows a project's build status, like the main project page, pipelines, commits, etc. This is on a from-source installation with Postgresql 9.6.1.
Steps to reproduce
Just updated from-source installation to 8.15, and tried to view the project information or commits on any project. This is on an Arch Linux system, using Postgresql 9.6.1 and Ruby 2.3.3.
Expected behavior
Project overview (or whichever page) for the selected project should display properly.
Actual behavior
"Something went wrong (500)" error page.
Relevant logs and/or screenshots
(I've redacted particular project names and IP addresses, let me know if you think those are necessary.)
Started GET "/XXXX/YYYY" for AAA.BBB.CCC.DDD at 2016-12-23 14:13:17 -0500
Processing by ProjectsController#show as HTML
Parameters: {"namespace_id"=>"XXXX", "id"=>"YYYY"}
Completed 500 Internal Server Error in 925ms (ActiveRecord: 54.2ms)
ActionView::Template::Error (PG::GroupingError: ERROR: column "ci_commits.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 2: ..."ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commit...
^
: SELECT (CASE
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'skipped' ORDER BY "ci_commits"."id" DESC) THEN 'skipped'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'success' ORDER BY "ci_commits"."id" DESC) THEN 'success'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'created' ORDER BY "ci_commits"."id" DESC) THEN 'created'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'success' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'skipped' ORDER BY "ci_commits"."id" DESC) THEN 'success'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'success' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'skipped' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'canceled' ORDER BY "ci_commits"."id" DESC) THEN 'canceled'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC)=(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'created' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'skipped' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'pending' ORDER BY "ci_commits"."id" DESC) THEN 'pending'
WHEN (SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'running' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'pending' ORDER BY "ci_commits"."id" DESC)+(SELECT count(*) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' AND "ci_commits"."ref" = 'master' AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = 86 AND "ci_commits"."sha" = 'c2704c7aec409b49adda00a730c028ba5a9f163c' GROUP BY "ci_commits"."ref", "ci_commits"."sha") AND "ci_commits"."status" = 'created' ORDER BY "ci_commits"."id" DESC)>0 THEN 'running'
ELSE 'failed'
END) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = $1 AND "ci_commits"."sha" = $2 AND "ci_commits"."ref" = $3 AND "ci_commits"."id" IN (SELECT max("ci_commits".id) FROM "ci_commits" WHERE "ci_commits"."gl_project_id" = $4 AND "ci_commits"."sha" = $5 GROUP BY "ci_commits"."ref", "ci_commits"."sha") ORDER BY "ci_commits"."id" DESC):
1:
2: - ref = local_assigns.fetch(:ref)
3: - status = commit.status(ref)
4: - if status
5: = link_to pipelines_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{status}" do
6: = ci_icon_for_status(status)
app/models/concerns/has_status.rb:38:in `status'
app/models/ci/pipeline.rb:101:in `latest_status'
app/models/commit.rb:233:in `status'
app/views/projects/_last_commit.html.haml:3:in `_app_views_projects__last_commit_html_haml___4504238517291325919_63815360'
app/views/projects/show.html.haml:78:in `_app_views_projects_show_html_haml___177420982280147825_88910420'
lib/gitlab/middleware/multipart.rb:93:in `call'
lib/gitlab/request_profiler/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:16:in `call'
Output of checks
Results of GitLab application Check
Init script is missing since I am using my own systemd service script.
Checking GitLab Shell ...
GitLab Shell version >= 4.1.1 ? ... OK (4.1.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
15/3 ... ok
15/5 ... ok
5/7 ... ok
15/10 ... ok
6/11 ... ok
5/12 ... ok
6/13 ... ok
5/14 ... ok
5/15 ... ok
10/17 ... ok
8/18 ... ok
10/21 ... ok
10/22 ... ok
10/23 ... ok
10/24 ... ok
10/25 ... ok
6/26 ... ok
15/28 ... ok
14/31 ... ok
8/32 ... ok
15/34 ... ok
8/35 ... ok
14/36 ... ok
16/37 ... ok
14/38 ... ok
3/40 ... ok
18/42 ... ok
14/43 ... ok
18/44 ... ok
19/47 ... ok
19/48 ... ok
19/49 ... ok
17/50 ... ok
18/52 ... ok
16/53 ... ok
17/54 ... ok
17/55 ... ok
15/57 ... ok
6/58 ... ok
16/59 ... ok
18/60 ... ok
18/61 ... ok
18/62 ... ok
18/63 ... ok
19/64 ... ok
16/65 ... ok
21/66 ... ok
21/67 ... ok
19/68 ... ok
19/69 ... ok
19/70 ... ok
16/72 ... ok
18/73 ... ok
15/74 ... ok
19/75 ... ok
25/77 ... ok
25/78 ... ok
25/82 ... ok
21/83 ... ok
21/84 ... ok
21/85 ... ok
18/86 ... ok
21/87 ... ok
6/88 ... ok
6/89 ... ok
18/90 ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /home/git/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Reply by email ...
Reply by email is disabled in config/gitlab.yml
Checking Reply by email ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured with autocrlf=input? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... yes
Init script exists? ... no
Try fixing it:
Install the init script
For more information see:
doc/install/installation.md in section "Install Init Script"
Please fix the error above and rerun the checks.
Init script up-to-date? ... can't check because of previous errors
projects have namespace: ...
15/3 ... yes
15/5 ... yes
5/7 ... yes
15/10 ... yes
6/11 ... yes
5/12 ... yes
6/13 ... yes
5/14 ... yes
5/15 ... yes
10/17 ... yes
8/18 ... yes
10/21 ... yes
10/22 ... yes
10/23 ... yes
10/24 ... yes
10/25 ... yes
6/26 ... yes
15/28 ... yes
14/31 ... yes
8/32 ... yes
15/34 ... yes
8/35 ... yes
14/36 ... yes
16/37 ... yes
14/38 ... yes
3/40 ... yes
18/42 ... yes
14/43 ... yes
18/44 ... yes
19/47 ... yes
19/48 ... yes
19/49 ... yes
17/50 ... yes
18/52 ... yes
16/53 ... yes
17/54 ... yes
17/55 ... yes
15/57 ... yes
6/58 ... yes
16/59 ... yes
18/60 ... yes
18/61 ... yes
18/62 ... yes
18/63 ... yes
19/64 ... yes
16/65 ... yes
21/66 ... yes
21/67 ... yes
19/68 ... yes
19/69 ... yes
19/70 ... yes
16/72 ... yes
18/73 ... yes
15/74 ... yes
19/75 ... yes
25/77 ... yes
25/78 ... yes
25/82 ... yes
21/83 ... yes
21/84 ... yes
21/85 ... yes
18/86 ... yes
21/87 ... yes
6/88 ... yes
6/89 ... yes
18/90 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.3)
Your git bin path is "/usr/bin/git"
Git version >= 2.7.3 ? ... yes (2.11.0)
Active users: 4
Checking GitLab ... Finished
Results of GitLab environment info
System:
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.5.2
Bundler Version:1.13.6
Rake Version: 10.5.0
Sidekiq Version:4.2.7
GitLab information
Version: 8.15.0
Revision: 4d3094149c
Directory: /home/git/gitlab
DB Adapter: postgresql
URL: XXX
HTTP Clone URL: XXX/some-group/some-project.git
SSH Clone URL: XXX:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 4.1.1
Repository storage paths:
- default: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
Possible fixes
From the stack trace, it appears app/models/concerns/has_status.rb
is to blame.