GraphQL is still not supported in Django 4, so to use it I need to change the line:
"from django.utils.encoding import force_text"
to
"from django.utils.encoding import force_str as force_text"
in package
"VENV/lib/PYTHON_VERSION/site-packages/graphene_django/utils/utils.py"
The problem occurs when using Docker, how could I replace this line when building the container?
2
Answers
Simply combine
RUN
with ased
-replace in your dockerfile.Replace
<PATH_TO_utils.py>
with the path toutils.py
Instead of manually changing the python module in site-packages, and assuming there’s no other way to fix this (i.e. if all you need is
force_text
to be defined atdjango.utils.encoding
), you could also write a "monkey patch", i.e. a runtime patch of thedjango.utils.encoding
module. Adding something like this in our own code (untested):Later, once not needed, this patch should be removed.