500 error caused by "expressions must appear in select list" SQL error when filtering issues and merge requests by release
Summary
When filtering issues with the newly added filter by Release feature that was added in 12.6, the customer is getting a 500 error in GitLab
Steps to reproduce
I have not been able to reproduce this on a test instance, but the steps the customer is taking is:
- Going to the issues section of GitLab
- Clicking in the search bar and selecting 'releases' from the drop down
- Selecting a release tag
What is the current bug behavior?
GitLab throws a 500 error and the customer is shown the Whoops, something went wrong on our end.
Page.
This only happens on Issue filtering and not Merge Request filtering.
There is also a SQL error thrown in the Postgres logs:
STATEMENT: SELECT DISTINCT "issues".* FROM "issues" JOIN milestone_releases ON issues.milestone_id = milestone_releases.milestone_id
2020-01-21_02:27:52.11676 JOIN releases ON milestone_releases.release_id = releases.id WHERE "issues"."project_id" = 313 AND ("issues"."state_id" IN (1)) AND "releases"."tag" = 'v1.7.20' AND "releases"."project_id" = 313 ORDER BY CASE WHEN issues.due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - issues.due_date) ASC LIMIT 20 OFFSET 0
2020-01-21_02:28:42.63004 ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list at character 340
What is the expected correct behavior?
The customer is able to click a release tag and filter while filtering issues.
Relevant logs and/or screenshots
production_json.log
{
"method": "GET",
"path": "/group/project/issues",
"format": "html",
"controller": "Projects::IssuesController",
"action": "index",
"status": 500,
"duration": 518.7,
"view": 0,
"db": 48.13,
"time": "2020-01-21T02:28:42.632Z",
"params": [
{
"key": "scope",
"value": "all"
},
{
"key": "utf8",
"value": "✓"
},
{
"key": "state",
"value": "opened"
},
{
"key": "release_tag",
"value": "v1.0.0"
},
{
"key": "namespace_id",
"value": "namespace"
},
{
"key": "project_id",
"value": "project_id"
}
],
"remote_ip": "172.20.122.71",
"user_id": 2,
"username": "2008517",
"ua": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
"queue_duration": 4.21,
"correlation_id": "CxD3068Zhy1",
"cpu_s": 0.670746565,
"exception.class": "ActiveRecord::StatementInvalid",
"exception.message": "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list\nLINE 2: ...1.0.0' AND \"releases\".\"project_id\" = 313 ORDER BY CASE WHEN ...\n ^\n: SELECT DISTINCT \"issues\".* FROM \"issues\" JOIN milestone_releases ON issues.milestone_id = milestone_releases.milestone_id\n JOIN releases ON milestone_releases.release_id = releases.id WHERE \"issues\".\"project_id\" = 313 AND (\"issues\".\"state_id\" IN (1)) AND \"releases\".\"tag\" = 'v1.0.0' AND \"releases\".\"project_id\" = 313 ORDER BY CASE WHEN issues.due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - issues.due_date) ASC LIMIT 20 OFFSET 0",
"exception.backtrace": [
"lib/gitlab/issuable_metadata.rb:18:in `map'",
"lib/gitlab/issuable_metadata.rb:18:in `issuable_meta_data'",
"app/controllers/concerns/issuable_collections.rb:47:in `set_pagination'",
"app/controllers/concerns/issuable_collections.rb:22:in `set_issuables_index'",
"ee/lib/gitlab/ip_address_state.rb:10:in `with'",
"ee/app/controllers/ee/application_controller.rb:43:in `set_current_ip_address'",
"lib/gitlab/session.rb:11:in `with_session'",
"app/controllers/application_controller.rb:458:in `set_session_storage'",
"app/controllers/application_controller.rb:452:in `set_locale'",
"lib/gitlab/error_tracking.rb:34:in `with_context'",
"app/controllers/application_controller.rb:536:in `sentry_context'",
"ee/lib/gitlab/jira/middleware.rb:19:in `call'"
]
}
production.log:
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 519ms (ActiveRecord: 48.1ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 33ms (ActiveRecord: 4.4ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 55ms (ActiveRecord: 8.9ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 53ms (ActiveRecord: 8.3ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 272ms (ActiveRecord: 5.2ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 33ms (ActiveRecord: 4.9ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Completed 500 Internal Server Error in 109ms (ActiveRecord: 19.0ms | Elasticsearch: 0.0ms)
ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
lib/gitlab/error_tracking.rb:34:in `with_context'
Output of checks
This error happens on GitLab.com also.
Sentry: https://sentry.gitlab.net/gitlab/gitlabcom/issues/1173130/events/23856028/
Kibana: https://log.gitlab.net/goto/2341ef0d734bccdfc51d18e73503cea0
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:env:info
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
)System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 2.6.3p62 Gem Version: 2.7.9 Bundler Version:1.17.3 Rake Version: 12.3.3 Redis Version: 3.2.12 Git Version: 2.24.1 Sidekiq Version:5.2.7 Go Version: unknown GitLab information Version: 12.6.4-ee Revision: cc6b787e7b0 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 10.9 URL: https://<gitlab_url:group/project> HTTP Clone URL: https://<gitlab_url:group/project> SSH Clone URL: git@<gitlab_url:group/project> Elasticsearch: no Geo: no Using LDAP: yes Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 10.3.0 Repository storage paths: - default: /data/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
GitLab Shell: ... GitLab Shell version >= 10.3.0 ? ... OK (10.3.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Gitaly ... Gitaly: ... default ... OK Checking Gitaly ... Finished Checking Sidekiq ... Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking Incoming Email ... Incoming Email: ... Reply by email is disabled in config/gitlab.yml Checking Incoming Email ... Finished Checking LDAP ... LDAP: ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) User output sanitized. Found 100 users of 100 limit. Checking LDAP ... Finished Checking GitLab App ... Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... <All passed with yes> Redis version >= 2.8.0? ... yes Ruby version >= 2.5.3 ? ... yes (2.6.3) Git version >= 2.22.0 ? ... yes (2.24.1) Git user has default SSH configuration? ... yes Active users: ... 153 Is authorized keys file accessible? ... yes Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled) Checking GitLab App ... Finished Checking GitLab subtasks ... Finished
/cc @jmeshell