Skip to content

Commit 8a21e90

Browse files
committed
Improved HttpQueryError hashing
1 parent a51bd66 commit 8a21e90

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

graphql_server/error.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import json
2-
3-
41
class HttpQueryError(Exception):
52
def __init__(self, status_code, message=None, is_graphql_error=False, headers=None):
63
self.status_code = status_code
@@ -10,10 +7,17 @@ def __init__(self, status_code, message=None, is_graphql_error=False, headers=No
107
super(HttpQueryError, self).__init__(message)
118

129
def __eq__(self, other):
13-
return isinstance(other, HttpQueryError) and \
14-
other.status_code == self.status_code and \
15-
other.message == self.message and \
16-
other.headers == self.headers
10+
return (
11+
isinstance(other, HttpQueryError)
12+
and other.status_code == self.status_code
13+
and other.message == self.message
14+
and other.headers == self.headers
15+
)
1716

1817
def __hash__(self):
19-
return hash((self.status_code, self.message, json.dumps(self.headers)))
18+
if self.headers:
19+
headers_hash = tuple(self.headers.items())
20+
else:
21+
headers_hash = None
22+
23+
return hash((self.status_code, self.message, headers_hash))

0 commit comments

Comments
 (0)