Skip to content

Handle serialization of standard library Enum values #140

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

Merged
merged 3 commits into from
Jul 19, 2018
Merged

Handle serialization of standard library Enum values #140

merged 3 commits into from
Jul 19, 2018

Conversation

descawed
Copy link

@descawed descawed commented Oct 2, 2017

This is my attempt at fixing graphql-python/graphene#547. dpnova's patch (#139) apparently breaks when GraphQLEnumType.serialize() is called with a value that is not an Enum instance, although I'm not sure when that happens, since it doesn't seem to be the case with GraphQL Enum types. This patch checks if the value is an Enum instance first, and retains the current behavior if not.

@descawed
Copy link
Author

descawed commented Oct 2, 2017

After additional review, I realized that pyutils.enum exists only in graphene, not graphql-core. I removed the fallback if the standard library Enum can't be found and reverted to the original behavior in this case. I think it should be possible to have graphene's pyutils.enum implement collections.Hashable, which would make it compatible with this code, but I'm not very familiar with metaclasses and I wasn't successful trying to add this myself.

@lincolnq
Copy link

This seems more right to me than the other proposals I found at graphql-python/graphene#559 and graphql-python/graphql-core#139. I'd be in favor of merging something like this

@dpnova
Copy link

dpnova commented Oct 19, 2017

Upon review, this looks great to me. Happy to bin #139 for this.

@jshearer
Copy link

jshearer commented Jun 1, 2018

Will this ever get merged?

olivierphi referenced this pull request in olivierphi/goodauldbooks Jul 17, 2018
…gREST calls replaced with GraphQL ones

Also circumvent the bug we face with Graphene Python Enums
(@link graphql-python/graphql-core#140)
@syrusakbary syrusakbary force-pushed the master branch 3 times, most recently from b1f26c1 to a7ce75e Compare July 19, 2018 18:24
@syrusakbary
Copy link
Member

I'm fixing few issues and merging it soon, so it will be released in 2.1.

@syrusakbary syrusakbary merged commit 24687b6 into graphql-python:master Jul 19, 2018
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.

5 participants