graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

Django v.4.0 and graphene-django v.2.15.0

Open hannody opened this issue 3 years ago • 26 comments

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)

hannody avatar Dec 11 '21 07:12 hannody

Got the same issue.

nngeno92 avatar Dec 13 '21 13:12 nngeno92

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

cjfd481980 avatar Dec 15 '21 01:12 cjfd481980

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.

ncdanie avatar Dec 23 '21 12:12 ncdanie

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

nirajhi avatar Dec 26 '21 13:12 nirajhi

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

Behoston avatar Dec 30 '21 18:12 Behoston

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

angelhvargas avatar Jan 02 '22 21:01 angelhvargas

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.

rishindoshi avatar Jan 13 '22 18:01 rishindoshi

Bump on this as well.

Antsthebul avatar Jan 23 '22 19:01 Antsthebul

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.

jyotendra avatar Jan 24 '22 11:01 jyotendra

Bump on this.

insomniac34 avatar Jan 24 '22 16:01 insomniac34

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

mnieber avatar Feb 05 '22 07:02 mnieber

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

ulgens avatar Feb 07 '22 14:02 ulgens

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

jeremystretch avatar Feb 07 '22 16:02 jeremystretch

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

ryanmerolle avatar Mar 08 '22 14:03 ryanmerolle

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

ulgens avatar Mar 08 '22 14:03 ulgens

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

ryanmerolle avatar Mar 08 '22 14:03 ryanmerolle

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?

jeremystretch avatar Mar 23 '22 20:03 jeremystretch

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

sbhatm1213 avatar Apr 12 '22 10:04 sbhatm1213

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

ryanmerolle avatar May 17 '22 20:05 ryanmerolle

Any update on this?

patvdleer avatar Jun 07 '22 18:06 patvdleer

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

insomniac34 avatar Jun 22 '22 03:06 insomniac34

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

ryanmerolle avatar Jun 30 '22 01:06 ryanmerolle

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.

Luferov avatar Jun 30 '22 10:06 Luferov

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

everdrone avatar Jul 01 '22 08:07 everdrone

i have same problem. Django==4.1 Python 3.10.5

There is no solution?

webafra avatar Aug 31 '22 16:08 webafra

@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

jeremystretch avatar Aug 31 '22 17:08 jeremystretch

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.

capital-G avatar Sep 25 '22 12:09 capital-G

@capital-G https://github.com/graphql-python/graphene-django/issues/705#issuecomment-1256997177 There is a discussion about what is going on with the project, you may want to follow it 🌷

ulgens avatar Sep 25 '22 12:09 ulgens

This issue should be resolved by https://github.com/graphql-python/graphene-django/pull/1275 and the latest release.

ulgens avatar Oct 31 '22 13:10 ulgens