Skip to content

Commit

Permalink
Fix possible sort error in build_response (#68)
Browse files Browse the repository at this point in the history
It seems that under certain circumstances, the list of errors can contain both located and unlocated errors, in which case using `locations` and `path` as sort key can fail, since in Python 3 you cannot compare a list with None. This fix makes sure that we always compare lists. The `path` can actually contain both int and str values, which cannot be compared either, but different types should not appear in a path where all parts of the path before are equal, which would be the only problematic case when sorting. So adding the path to the sort key should be safe.
  • Loading branch information
Esteban Echeverry authored and Cito committed Nov 28, 2019
1 parent a128ee0 commit 07a4cfa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/graphql/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ async def build_response_async():
return ExecutionResult(data, None)
# Sort the error list in order to make it deterministic, since we might have
# been using parallel execution.
errors.sort(key=lambda error: (error.locations, error.path, error.message))
errors.sort(
key=lambda error: (error.locations or [], error.path or [], error.message)
)
return ExecutionResult(data, errors)

def execute_operation(
Expand Down

0 comments on commit 07a4cfa

Please sign in to comment.