I'm developing an app using Django + Strawberry + Channels.
Until the introduction of Channels and related logic to manage subscriptions, I used a custom decorator to populate the info.context
object of some selected queries and mutations with some extra stuff.
To be clear, something like this:
from functools import wraps
def my_decorator(funct):
@wraps(funct)
def my_wrapper(info, *args, **kwargs):
info.context.my_property = get_some_extra_property()
return funct(info, *args, **kwargs)
return my_wrapper
It has always worked fine since the context
is a StrawberryDjangoContext
dataclass object.
Now...
After introducing support for subscriptions, I ran into an exception: it seems that the context
instantiated by GraphQLView
is actually different from the one instantiated by GraphQLHTTPConsumer
...
Even though they both only expose 2 properties: request
& response
.
The second one -unlike the first one- instantiates a simple dict
and this led the application to raise a:
AttributeError: 'dict' object has no attribute 'my_property'.
To be honest, I've already fixed my application so that's ok but this difference triggers my OCDs, IMHO isn't really a good thing for a library and it creates user confusion and that's why I opened this Issue.
Make your own consideration and choose whatever approach you like... It's just a simple report.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too