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

gives this error ImportError: cannot import name 'is_async' from 'strawberry_django.utils' #414

Open
deepak7448 opened this issue Jul 24, 2023 · 2 comments

Comments

@deepak7448
Copy link

Screenshot from 2023-07-24 14-15-30

When I'm importing this - from strawberry_django_jwt.decorators import login_required
then its gives this error ImportError: cannot import name 'is_async' from 'strawberry_django.utils'

@Aeonian9
Copy link

Aeonian9 commented Jan 9, 2024

Workaround when upgrading package versions and not running async Django.

Run this code before strawberry_django_jwt is initiated. For example in the beginning of urls.py.

import strawberry_django.utils
def fix_is_async(*args, **kwargs):
    return False
strawberry_django.utils.is_async = fix_is_async

@advl
Copy link

advl commented Jul 1, 2024

Here's how I fixed it

import asyncio

def is_async() -> bool:                                                         
    """
    Helper function to determine if the current context is asynchronous.
     
    :return: True if the current asyncio event loop is running, False otherwise.
    """
    try:
        loop = asyncio.get_running_loop()
        return loop.is_running()
    except RuntimeError:
        return False
    return False

Currently working on a fork lib towards a stable django 4 & 5 only build, updating deps, keeping the same API surface.

In case you're trying to do the same at home,

  1. I have not encountered any issue in getting the lib to work on Django 5 & the newest versions of strawberry libs aside from the one on this post.
  2. Deps updates are probably the most tricky, and dropping support for Django 3 (not because intrinsically being incompatible, but because of the lock tree creating issues) helped
  3. This library is partially typed. Overall the codebase seems stable and clean, as it's been there under the graphene version for quite some time.
  4. The codebase has little documentation, but the original docs - for graphene - seem to me good quality.

If successful in getting something clean, will release it publicly. Lmk if interested or willing to contribute to that - setting up sth on discord ?

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

No branches or pull requests

3 participants