Skip to content

Commit 07a4cfa

Browse files
Esteban EcheverryCito
Esteban Echeverry
authored andcommitted
Fix possible sort error in build_response (#68)
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.
1 parent a128ee0 commit 07a4cfa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/graphql/execution/execute.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ async def build_response_async():
315315
return ExecutionResult(data, None)
316316
# Sort the error list in order to make it deterministic, since we might have
317317
# been using parallel execution.
318-
errors.sort(key=lambda error: (error.locations, error.path, error.message))
318+
errors.sort(
319+
key=lambda error: (error.locations or [], error.path or [], error.message)
320+
)
319321
return ExecutionResult(data, errors)
320322

321323
def execute_operation(

0 commit comments

Comments
 (0)