Exception when filtering epics in list with 2 labels and search text
Filtering the epics list using two labels and a search term causes an exception.
To reproduce
- Go to gitlab.com/groups/gitlab-org/-/epics
- Enter any two labels in the search box
- Add some search text and hit enter
Stack trace from Sentry
https://sentry.gitlab.net/gitlab/gitlabcom/issues/1180988/
PG::GroupingError: ERROR: column "epics.group_id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...49, 6908664, 6087278, 6911764, 6087282))) SELECT "epics".* ...
^
active_record/connection_adapters/postgresql_adapter.rb:611:in `async_exec_params'
@connection.exec_params(sql, type_casted_binds)
active_record/connection_adapters/postgresql_adapter.rb:611:in `block (2 levels) in exec_no_cache'
@connection.exec_params(sql, type_casted_binds)
active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
yield
active_support/concurrency/share_lock.rb:187:in `yield_shares'
yield
active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
@lock.yield_shares(compatible: [:load]) do
...
(162 additional frame(s) were not displayed)
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "epics.group_id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...49, 6908664, 6087278, 6911764, 6087282))) SELECT "epics".* ...
^
: WITH "epics" AS ((SELECT "epics".* FROM "epics" WHERE "epics"."group_id" IN (9970, 1540914, 1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837, 2907304, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433, 4834769, 4955423, 4982080, 5032027, 5086830, 5387503, 5429390, 5551887, 5700593, 5754519, 6089080, 6104555, 6185122, 6382519, 6443980, 6511126, 6522059, 6564587, 4017478, 4786315, 5496663, 1920510, 2873631, 4702954, 5849956, 5920126, 6087276, 6403257, 6891108, 6891292, 6911758, 2584649, 2504721, 2564205, 2626771, 3450127, 5715594, 5595721, 5769520, 5927369, 5927426, 3887968, 5924764, 6150316, 5878052, 6762309, 4006638, 5255563, 4834773, 5907869, 6417478, 5999875, 5108088, 6883745, 6883788, 6884402, 6884525, 6884549, 6908664, 6087278, 6911764, 6087282))) SELECT "epics".* FROM epics INNER JOIN "label_links" ON "label_links"."target_id" = "epics"."id" AND "label_links"."target_type" = 'Epic' INNER JOIN "labels" ON "labels"."id" = "label_links"."label_id" WHERE ("epics"."title" ILIKE '%python%' OR "epics"."description" ILIKE '%python%') AND "epics"."state_id" = 1 AND "labels"."title" IN ('devops::secure', 'Category:Dependency Scanning') GROUP BY "epics"."id" HAVING (COUNT(DISTINCT labels.title) = 2) ORDER BY "epics"."created_at" DESC, "epics"."id" DESC LIMIT 20 OFFSET 0
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "epics.group_id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...49, 6908664, 6087278, 6911764, 6087282))) SELECT "epics".* ...
^
: WITH "epics" AS ((SELECT "epics".* FROM "epics" WHERE "epics"."group_id" IN (9970, 1540914, 1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837, 2907304, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433, 4834769, 4955423, 4982080, 5032027, 5086830, 5387503, 5429390, 5551887, 5700593, 5754519, 6089080, 6104555, 6185122, 6382519, 6443980, 6511126, 6522059, 6564587, 4017478, 4786315, 5496663, 1920510, 2873631, 4702954, 5849956, 5920126, 6087276, 6403257, 6891108, 6891292, 6911758, 2584649, 2504721, 2564205, 2626771, 3450127, 5715594, 5595721, 5769520, 5927369, 5927426, 3887968, 5924764, 6150316, 5878052, 6762309, 4006638, 5255563, 4834773, 5907869, 6417478, 5999875, 5108088, 6883745, 6883788, 6884402, 6884525, 6884549, 6908664, 6087278, 6911764, 6087282))) SELECT "epics".* FROM epics INNER JOIN "label_links" ON "label_links"."target_id" = "epics"."id" AND "label_links"."target_type" = 'Epic' INNER JOIN "labels" ON "labels"."id" = "label_links"."label_id" WHERE ("epics"."title" ILIKE '%python%' OR "epics"."description" ILIKE '%python%') AND "epics"."state_id" = 1 AND "labels"."title" IN ('devops::secure', 'Category:Dependency Scanning') GROUP BY "epics"."id" HAVING (COUNT(DISTINCT labels.title) = 2) ORDER BY "epics"."created_at" DESC, "epics"."id" DESC LIMIT 20 OFFSET 0
Edited by John Hope