Panic in GraphQL server when sorting on multiple fields, using query variables

Hi,

Since I moved from DGraph v20.11.0 to the latest v20.11.1, I started experiencing a panic causing the server to exit!

It happens systematically when I execute a query with a sort criteria on multiple fields.
The same query with a single sorted field works just fine, and it used to work perfectly with the previous version.
I also, recreated a brand new database in order to verify that it was not caused by the upgrade but the crash happened in both cases.

Here’s the query:

query($first: Int, $workloadOrder: KubeWorkloadOrder) {
  queryKubeWorkload(first: $first, order: $workloadOrder) {
    id
  }

with the following variables:

{
    "first": 10,
    "workloadOrder": {
      "asc": "_namespaceName",
      "then": {
        "asc": "_type"
      }
    }
  }

And here’s the log of the server:

I0208 05:33:39.690260      41 admin.go:709] Successfully loaded GraphQL schema.  Serving GraphQL API.
I0208 05:34:07.399370      41 admin.go:509] Updating GraphQL schema from subscription.
I0208 05:34:07.399570      41 admin.go:539] Skipping GraphQL schema update, new badger key version is 19, the old version was 0.
I0208 05:34:29.437018      33 raft.go:719] Skipping creating a snapshot. Num groups: 1, Num checkpoints: 0
2021/02/08 05:38:06 Assert failed
github.com/dgraph-io/dgraph/x.AssertTrue
	/ext-go/1/src/github.com/dgraph-io/dgraph/x/error.go:100
github.com/dgraph-io/dgraph/worker.multiSort
	/ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:371
github.com/dgraph-io/dgraph/worker.processSort
	/ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:531
github.com/dgraph-io/dgraph/worker.SortOverNetwork
	/ext-go/1/src/github.com/dgraph-io/dgraph/worker/sort.go:70
github.com/dgraph-io/dgraph/query.(*SubGraph).applyOrderAndPagination
	/ext-go/1/src/github.com/dgraph-io/dgraph/query/query.go:2362
github.com/dgraph-io/dgraph/query.ProcessGraph
	/ext-go/1/src/github.com/dgraph-io/dgraph/query/query.go:2204
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1374

Note that when I remove the “first: $first,” argument it will work just fine.
Also, if I remove the variables like this:

query {
  queryKubeWorkload(offset: 10, order: {
      asc: _namespaceName,
      then: {
        asc: _type
      }}) {
    id
  }
}

it works perfectly too!

Hey @livetocode, welcome to the forums! It would appear this might be a bug (or at least this should not happen).

pinging @ibrahim for more info

@pawan is our query expert. I wonder why this

would fail.

Duplicate of Sorting on multiple predicates broken on 20.11.1

Looks like this was fixed via fix(sort): Fix multi-sort with nils by ahsanbarkati · Pull Request #7432 · dgraph-io/dgraph · GitHub

@livetocode please try out this PR. This will be part of the next release of dgraph.

1 Like