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

Django v.4.0 and graphene-django v.2.15.0 #1284

Closed
hannody opened this issue Dec 11, 2021 · 29 comments
Closed

Django v.4.0 and graphene-django v.2.15.0 #1284

hannody opened this issue Dec 11, 2021 · 29 comments
Labels

Comments

@hannody
Copy link

hannody commented Dec 11, 2021

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • What is the current behavior?

Running Django 4.0 server fails after adding/installing graphene-django v.2.15.0 to the project.
"ImportError: cannot import name 'force_text' from 'django.utils.encoding'"

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    a github repo, https://repl.it or similar (you can use this template as a starting point: https://repl.it/@jkimbo/Graphene-Django-Example).

  • **Steps to reproduce:
    1- mkvirtualenv dj4
    2- pip install django
    3- django-admin startproject core .
    4- python manage.py runserver (Django server is up and running)
    5- pip install graphene-django
    6- python manage.py runserver ( ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/utils/encoding.py)

  • What is the expected behavior?

Django server should be up and running. downgrading django to 3.2.9 will make the project works!

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

    • Version: Python 3.8, Django 4.0, graphene-django v.2.15.0
    • Platform: Ubuntu 20.04
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

  • **Stacktrace
    $ python manage.py runserver
    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
    File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
    File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 115, in inner_run
    autoreload.raise_last_exception()
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/core/management/init.py", line 381, in execute
    autoreload.check_errors(django.setup)()
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/init.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/apps/config.py", line 223, in create
    import_module(entry)
    File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "", line 1014, in _gcd_import
    File "", line 991, in _find_and_load
    File "", line 975, in _find_and_load_unlocked
    File "", line 671, in _load_unlocked
    File "", line 848, in exec_module
    File "", line 219, in _call_with_frames_removed
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/graphene_django/init.py", line 1, in
    from .fields import DjangoConnectionField, DjangoListField
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/graphene_django/fields.py", line 18, in
    from .utils import maybe_queryset
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/graphene_django/utils/init.py", line 2, in
    from .utils import (
    File "/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/graphene_django/utils/utils.py", line 6, in
    from django.utils.encoding import force_text
    ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/home/fake_user/.virtualenvs/dj4/lib/python3.8/site-packages/django/utils/encoding.py)

@nngeno92
Copy link

Got the same issue.

@cjfd481980
Copy link

def force_text(s, encoding='utf-8', strings_only=False, errors='strict'): warnings.warn( 'force_text() is deprecated in favor of force_str().', RemovedInDjango40Warning, stacklevel=2, ) return force_str(s, encoding, strings_only, errors)
found this on django=3.2 django/utils/encoding.py line 110

@ncdanie
Copy link

ncdanie commented Dec 23, 2021

I followed an answer on this stackoverflow post to resolve the issue:
https://stackoverflow.com/questions/70382084/import-error-force-text-from-django-utils-encoding/70389991#70389991
Change an import statement in site-packages/graphene_django/utils/utils.py so that it imports force_str and not force_text.

@nirajhi
Copy link

nirajhi commented Dec 26, 2021

Just started learning graphql using django-graphene. This issue was such a road blocker for me. :(

@Behoston
Copy link

version graphene-django==3.0.0b7 works with Django 4.0 but I really want to see new release (this beta version is 1yo)

@angelhvargas
Copy link

Can we get a new prod release to get Django 4.0 working?

@rishindoshi
Copy link

Bump on this! Having the same issue with Django 4.0. Really slowing down releases to staging/production since I have to hotfix the library code as per the stackoverflow post mentioned above.

@Antsthebul
Copy link

Bump on this as well.

@jyotendra
Copy link

jyotendra commented Jan 24, 2022

Till the PR gets merged, probably this monkeypatching might work (not tested in prod):

import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str

Put this in entryfile. I kept it in settings.py for time being.

@insomniac34
Copy link

Bump on this.

@mnieber
Copy link

mnieber commented Feb 5, 2022

The fix by @jyotendra worked for me. Another option is to put it in the __init__.py that is next to settings.py

@ulgens
Copy link
Collaborator

ulgens commented Feb 7, 2022

#1275 is merged. @hannody Can you please try it again?

@jeremystretch
Copy link

I can confirm that this is solved for me using commit a7a8b3d under Django 4.0.2 (pip install git+git://github.com/graphql-python/graphene-django.git@a7a8b3dca6cee0ac7e94833535fea65911b507ac).

@ryanmerolle
Copy link

Will 2.16 be released anytime soon? Django 4.0 support would be really nice.

@ulgens
Copy link
Collaborator

ulgens commented Mar 8, 2022

@ryanmerolle Working on it right now, i hope we will have something in a week 🌷

@ryanmerolle
Copy link

Much appreciated! I did not mean to come off as demanding or rude. I appreciate all the work you put into this project!

@jeremystretch
Copy link

Happy to help get this out the door if I can. IIRC there was some mention of wanting to clean up the test suite prior to releasing?

@sbhatm1213
Copy link

sbhatm1213 commented Apr 12, 2022

Having the same issue . Waiting for the next version.
Using the monkey patch method suggested by Jyotendra for the time being.

@ryanmerolle
Copy link

How goes everything @ulgens? Is there anyway any of us can help?

@patvdleer
Copy link

Any update on this?

@insomniac34
Copy link

@ulgens how is progress coming along on the latest release? Just curious if there's anything I could do to help!

@ryanmerolle
Copy link

ryanmerolle commented Jun 30, 2022

FYI if you have not seen the post, ulgens and team are stepping away from the project. This could get picked up by the larger graphql-python group, but still TBD. #1324

@Luferov
Copy link

Luferov commented Jun 30, 2022

FYI if you have not seen the post, ulgens and team are stepping away from the project. This could get picked up by the larger graphql-python group, but still TBD. #1324

Look, we will now gently transition from graphene_django to strawberry, we can share our experience if you are interested.
Because strawberries are healthier, more prosperous, and architecturally more advanced.

@everdrone
Copy link

everdrone commented Jul 1, 2022

@Luferov are you using Relay connections with strawberry?
From what I've seen on the repo the Relay spec is still to be implemented

@webafra
Copy link

webafra commented Aug 31, 2022

i have same problem.
Django==4.1
Python 3.10.5

There is no solution?

@jeremystretch
Copy link

@webafra You can work around it with a monkey patch in settings.py if you really need to, but recognize that it's a band-aid at best. (The below works for Django 4.0; haven't tested on Django 4.1.)

import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str

@capital-G
Copy link

I don't want to put too much pressure on the devs but is this project still maintained? Django 4.0 was released 10 months ago, yet the current default version on PyPi is still incompatible with Django 4.0, the advised quickstart installation also heads to a non-existing package.

venv ❯ pip3 install --upgrade "graphene-django>=3"          
ERROR: Could not find a version that satisfies the requirement graphene-django>=3 (from versions: 1.0.dev20160909000001, 1.0.dev20160910000001, 1.0.dev20160917000001, 1.0.dev20160919000001, 1.0.dev20160919000002, 1.0.dev20160919000003, 1.0.dev20160919000004, 1.0.dev20160920000001, 1.0.dev20160922000001, 1.0, 1.1.0, 1.2.0, 1.2.1, 1.3, 2.0.dev2017072501, 2.0.dev2017072601, 2.0.dev2017073101, 2.0.dev2017083101, 2.0.0, 2.1rc0, 2.1rc1, 2.1.0, 2.2.0, 2.3.0, 2.3.2, 2.4.0, 2.5.0, 2.6.0, 2.7.0, 2.7.1, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.12.0, 2.12.1, 2.13.0, 2.14.0, 2.15.0, 3.0.0b1, 3.0.0b2, 3.0.0b3, 3.0.0b4, 3.0.0b5, 3.0.0b6, 3.0.0b7, 3.0.0b8)
ERROR: No matching distribution found for graphene-django>=3

I currently evaluating a switch from DRF to GraphQL for a new project and this circumstance does not put much trust into this otherwise really fine looking project, but it also seems like abandon ware for this reason.

@ulgens
Copy link
Collaborator

ulgens commented Sep 25, 2022

@capital-G #705 (comment) There is a discussion about what is going on with the project, you may want to follow it 🌷

@ulgens
Copy link
Collaborator

ulgens commented Oct 31, 2022

This issue should be resolved by #1275 and the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests