DjangoChannelsGraphqlWs icon indicating copy to clipboard operation
DjangoChannelsGraphqlWs copied to clipboard

import side-effect disables promise trampoline breaking DataLoaders

Open AllexVeldman opened this issue 4 years ago • 7 comments

On import channels_graphql_ws, promise.promise.async_instance.disable_trampoline() is called, breaking DataLoaders.

In the code there is a reference to https://github.com/syrusakbary/promise/issues/57#issuecomment-406778476 which indicates this is needed due to Promise not being thread-safe.

This should no longer be needed with promise ^2.3 https://github.com/syrusakbary/promise/pull/81 https://github.com/syrusakbary/promise/releases/tag/v2.3.0

For some reason not completely clear to me yet this only impacts my unittests, the async_instance during normal operation seems to have trampoline_enabled=True.

AllexVeldman avatar Mar 19 '21 15:03 AllexVeldman

@alexmnazarenko Considering this thread-safe issue as fixed we can probably throw away invocation of disable_trampoline(). We need to be careful here, AFAIR it took significant about of time to debug this for the first time.

prokher avatar Mar 19 '21 20:03 prokher

We're seeing the exact same issue, enable_trampoline() fixed it

matclayton avatar Sep 16 '21 09:09 matclayton

@matclayton

We're seeing the exact same issue, enable_trampoline() fixed it

Any example of where you (or anyone else who happens upon this issue) placed the enable_trampoline() code?

(I assume if @AllexVeldman is correct on promise not needing it, doing it as early as possible would be best)

tony avatar Feb 01 '22 17:02 tony

For sure

class GraphQLConfig(AppConfig):
    name = "mixcloud.core.graphql"
    label = "graphql"

    def ready(self) -> None:
        # This is dangerous
        # This is to counteract https://github.com/datadvance/DjangoChannelsGraphqlWs/blob/master/channels_graphql_ws/graphql_ws_consumer.py#L165
        # DjangoChannelsGraphqlWs disables_trampoline, which by default prevents dataloaders and promises from working, t
        # This would cause a LOT of tests to fail,
        # We need to put this back to the original value after DjangoChannelsGraphqlWs has done the damage.
        # These is a plan to remove this from the base lib https://github.com/datadvance/DjangoChannelsGraphqlWs/issues/67
        # as promises 2.4+ is now thread safe, so their patch shouldn't be required anymore, enable_tramoline could be removed at that point.
        import promise

        promise.promise.async_instance.enable_trampoline()

We do this in an AppConfig, so its enabled at bootup

matclayton avatar Feb 02 '22 11:02 matclayton

@matclayton Thank you for this!

tony avatar Feb 02 '22 12:02 tony

For what it's worth, our (@tony and I) issue was this: https://github.com/graphql-python/graphql-core-legacy/pull/287

malthejorgensen avatar Mar 08 '22 13:03 malthejorgensen

Are there any plans to remove promise.promise.async_instance.disable_trampoline() in the next release?

adrienhongcs avatar Aug 09 '23 17:08 adrienhongcs