-
Notifications
You must be signed in to change notification settings - Fork 16
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
Alter endpoint context behavior. #125
base: master
Are you sure you want to change the base?
Alter endpoint context behavior. #125
Conversation
…text dict, use the old context dict and add the new data to that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, left a comment. Black 20 is out and it's breaking CI, we'd need to fix things separately.
Use a copy of the initial config instead of directly updating the initial config with the new values. Co-authored-by: Florimond Manca <[email protected]>
It was set to use config.context so fixed that and now everything is good. |
Oops, just realized I should add this behavior to the Subscriptions endpoint as well, will update with that in a bit. |
So it seems this hasn't fixed my issue but my initial method does. Edit: Example code for my custom context object. For reference, I was having this issue before with just a plain dictionary but attempted this as a solution.
|
@florimondmanca Do you have any thoughts on this? I'm having trouble coming up with a solution. |
@AutumnalDream Hi! Could you try by starting to explain what your initial problem / use case was? From the snippet of your custom context class, it seems you're trying to have a context per request, or at least "refresh" this context once a new request comes in. I'm not sure exactly what you're trying to do, but have you explored the |
Ya that is exactly it! My initial plan was to just make sure it was making a copy when it gets sent to the engine but perhaps also using So more of two separate things in this PR I guess. I've never written anything with the contextvars module but it looks like it could be the solution. |
So after messing around with contextvars for a bit I couldn't get it to work. But, I'm also a bit of an async noob and have never used contextvars before. But I did switch the code to use copy.deepcopy, and it works. |
@florimondmanca Looks like there is a flake8 issue on protocol.py, do you want me to put |
@florimondmanca Hi just checking if you saw this. |
@AutumnalDream Hi! Hmm yes I suppose we're having to deal with these new flake8-pie errors in this repo as well (they caught us in a few other repos I contribute to). Ideally we should go through a dedicated pull request to ignore them, to keep this one clean. |
Currently, in GraphQLEndpoint._get_response(), it makes a new dictionary and adds data from the provided context dictionary to it. This can be an issue if a custom dictionary class is provided as the context.
In my opinion as well it makes more sense to add to the provided dict instead of replacing it.
As far as I can tell I don't see any breaking issues with this change.
Also if I remember correctly, context is a dict in GraphQL spec maybe, but I don't think it is specified as anything in the Tartiflette code itself.
Edit: Including reason for this PR.
Basically, my reason for this issue is that it seems the context is being shared across requests.