Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __hash__ for GraphQLError #35

Merged
merged 5 commits into from
May 31, 2019

Conversation

andrew-humu
Copy link
Contributor

Fixes #34

This seemed like the most minimal implementation that might be safe, but it's definitely possible there's some context I'm missing. I also claim no mastery of python!

@Cito
Copy link
Member

Cito commented May 31, 2019

Thank your for providing this PR. Hashing only original_error assumes that one original error cannot cause two different GraphQLErrors, which is generally true, and that it is always set, which is not always the case. It would be better to derive the hash from all slotted attributes.

But I think the best and most performant solution is to simply use the default hash method for exceptions, based on the id of the instance. GraphQLError lost that default hash capability when it got a custom __eq__ method, but the default hash method can be restored by setting __hash__ = Exception.__hash__. Can you check if that works for you and change the PR accordingly?

@andrew-humu
Copy link
Contributor Author

Your reasoning makes a lot of sense to me. I pushed a commit — is this what you had in mind?

Copy link
Member

@Cito Cito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you.

@Cito Cito merged commit 6ddb125 into graphql-python:master May 31, 2019
@andrew-humu andrew-humu deleted the 34-hash-graphqlerror branch June 1, 2019 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQLError is unhashable
3 participants