GraphQL query to fetch Epics fails when `sort` and `last` params are provided together
Summary
When fetching Epics list using GraphQL, Internal Server Error
happens while running the query, following is the error trace;
ActiveRecord::IrreversibleOrderError (Order "start_date DESC NULLS LAST" cannot be reversed automatically): lib/gitlab/graphql/pagination/keyset/last_items.rb:17:in `take_items' lib/gitlab/graphql/pagination/keyset/connection.rb:113:in `block in limited_nodes' lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize' lib/gitlab/graphql/pagination/keyset/connection.rb:107:in `limited_nodes' lib/gitlab/graphql/pagination/keyset/connection.rb:100:in `nodes' lib/gitlab/graphql/authorize/authorize_field_service.rb:114:in `to_nodes' lib/gitlab/graphql/authorize/authorize_field_service.rb:87:in `block in filter_allowed' lib/gitlab/graphql/lazy.rb:17:in `block in then' lib/gitlab/graphql/lazy.rb:13:in `block in force' lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize' lib/gitlab/graphql/lazy.rb:13:in `force' lib/gitlab/graphql/generic_tracing.rb:48:in `with_labkit_tracing' lib/gitlab/graphql/generic_tracing.rb:30:in `platform_trace' lib/gitlab/graphql/generic_tracing.rb:48:in `with_labkit_tracing' lib/gitlab/graphql/generic_tracing.rb:30:in `platform_trace' lib/gitlab/graphql/generic_tracing.rb:48:in `with_labkit_tracing' lib/gitlab/graphql/generic_tracing.rb:30:in `platform_trace' app/graphql/gitlab_schema.rb:43:in `multiplex' app/graphql/gitlab_schema.rb:50:in `execute' app/controllers/graphql_controller.rb:71:in `execute_query' app/controllers/graphql_controller.rb:32:in `execute' ee/lib/gitlab/ip_address_state.rb:10:in `with' ee/app/controllers/ee/application_controller.rb:44:in `set_current_ip_address' app/controllers/application_controller.rb:493:in `set_current_admin' lib/gitlab/session.rb:11:in `with_session' app/controllers/application_controller.rb:484:in `set_session_storage' lib/gitlab/i18n.rb:73:in `with_locale' lib/gitlab/i18n.rb:79:in `with_user_locale' app/controllers/application_controller.rb:478:in `set_locale' lib/gitlab/error_tracking.rb:52:in `with_context' app/controllers/application_controller.rb:543:in `sentry_context' app/controllers/application_controller.rb:471:in `block in set_current_context' lib/gitlab/application_context.rb:54:in `block in use' lib/gitlab/application_context.rb:54:in `use' lib/gitlab/application_context.rb:21:in `with_context' app/controllers/application_controller.rb:463:in `set_current_context' lib/gitlab/metrics/elasticsearch_rack_middleware.rb:16:in `call' lib/gitlab/middleware/rails_queue_duration.rb:33:in `call' lib/gitlab/metrics/rack_middleware.rb:16:in `block in call' lib/gitlab/metrics/transaction.rb:61:in `run' lib/gitlab/metrics/rack_middleware.rb:16:in `call' lib/gitlab/request_profiler/middleware.rb:17:in `call' lib/gitlab/query_limiting/middleware.rb:17:in `block in call' lib/gitlab/query_limiting/transaction.rb:39:in `run' lib/gitlab/query_limiting/middleware.rb:16:in `call' lib/gitlab/jira/middleware.rb:19:in `call' lib/gitlab/middleware/go.rb:20:in `call' lib/gitlab/etag_caching/middleware.rb:13:in `call' lib/gitlab/middleware/multipart.rb:234:in `call' lib/gitlab/middleware/read_only/controller.rb:51:in `call' lib/gitlab/middleware/read_only.rb:18:in `call' lib/gitlab/middleware/same_site_cookies.rb:27:in `call' lib/gitlab/middleware/handle_malformed_strings.rb:19:in `call' lib/gitlab/middleware/basic_health_check.rb:25:in `call' lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call' lib/gitlab/middleware/request_context.rb:23:in `call' config/initializers/fix_local_cache_middleware.rb:9:in `call' lib/gitlab/middleware/static.rb:11:in `call' lib/gitlab/webpack/dev_server_middleware.rb:34:in `perform_request' lib/gitlab/metrics/requests_rack_middleware.rb:76:in `call' lib/gitlab/middleware/release_env.rb:12:in `call'
Following GraphQL query was used;
query groupEpics(
$groupPath: ID!
$state: EpicState
$labelName: [String!]
$sortBy: EpicSort
$firstPageSize: Int
$lastPageSize: Int
$prevPageCursor: String = ""
$nextPageCursor: String = ""
) {
group(fullPath: $groupPath) {
epics(
state: $state
labelName: $labelName
sort: $sortBy
first: $firstPageSize
last: $lastPageSize
after: $nextPageCursor
before: $prevPageCursor
) {
nodes {
id
iid
title
createdAt
updatedAt
startDate
dueDate
webUrl
author {
...Author
}
labels {
nodes {
...Label
}
}
discussions {
nodes {
id
}
}
}
pageInfo {
...PageInfo
}
}
}
}
And following variables were provided;
{
"groupPath": "gitlab-org",
"state": "opened",
"lastPageSize": 2,
"sortBy": "start_date_desc",
"prevPageCursor": "eyJpZCI6IjIiLCJzdGFydF9kYXRlIjoiMjAyMC0wNC0wMSJ9"
}
Please note that query runs fine if only one of either lastPageSize
or sortBy
is provided, it fails only when both are provided.