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

GraphQL schemas do not seem to be deep copyable #874

Closed
wants to merge 5 commits into from

Conversation

pmantica1
Copy link
Contributor

When I tried to optimize tests by using the deep copies, I got a ton of different errors. I thought that this was because of a compiler bug but it seems that this deepcopy somehow messes up the internals of GraphQLSchema.

While testing locally, test_normal_schema_comparison passed but test_deep_copy_comparison did not.

@obi1kenobi
Copy link
Contributor

obi1kenobi commented Jul 5, 2020 via email

@pmantica1
Copy link
Contributor Author

pmantica1 commented Jul 7, 2020

For the explanation below, please note that I now use a reduced version of the schema in this PR.

Ok so I think I figured out the problem or at least part of the problem with deepcopy.

The GraphQLSchema __init__ function uses a TypeSet that checks if two GraphQL types are equal by comparing their python object references. The __init__ function includes the builtin __Schema type is not already included in this TypeSet.

When we use deepcopy we generate new object references for all of the copied objects. So when we use the types in a deep-copied schema to build a lexicographically sorted schema, we call the GraphQLSchema __init__ function which doubly adds the __Schema type since the deep-copied __Schema type has a different reference than the original __Schema type. This in turns leads to an error later in the __init__ function call.

I suspect that other functions in the GraphQL core library might also refer to GraphQL types by their python object references. Unless the GraphQL library is patched to only refer to GraphQL types by their names, we are going to keep finding weird bugs like this one if we use a deep-copied schema.

I am going to submit an issue in the GraphQL core library. This refactor, however, probably won't be easy to make and might not even be wanted by maintainer. So I think that we'll probably want to go a different route for performance optimizing our tests. We should probably wait for the maintainer to respond to the issue though.

@pmantica1
Copy link
Contributor Author

Made an issue:
graphql-python/graphql-core#100

@pmantica1
Copy link
Contributor Author

Closing this PR since it doesn't really need review.

@pmantica1 pmantica1 closed this Jul 7, 2020
@pmantica1 pmantica1 deleted the graphql-schema-are-not-deep-copyable branch August 3, 2020 20:34
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.

2 participants