how to fix "TypeError: requires_system_checks must be a list or tuple." caused by "py manage.py grpcrunserver" command?

192 views Asked by At

it's my first time aksing a question here so please take easy on me if I do it bad (or whatever) and help! Thanks.

I have a project in which I need to use django_grpc_framework, and I've implemented the code but when I try to run the grpc server using "py manage.py grpcrunserver" I get the following error log:

(.venv) D:\Programming-stuff\PythonProjects\notification>py manage.py grpcrunserver
Traceback (most recent call last):
  File "D:\Programming-stuff\PythonProjects\notification\manage.py", line 22, in <module>
    main()
  File "D:\Programming-stuff\PythonProjects\notification\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "d:\Programming-stuff\PythonProjects\notification\.venv\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "d:\Programming-stuff\PythonProjects\notification\.venv\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Programming-stuff\PythonProjects\notification\.venv\Lib\site-packages\django\core\management\__init__.py", line 275, in fetch_command
    klass = load_command_class(app_name, subcommand)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Programming-stuff\PythonProjects\notification\.venv\Lib\site-packages\django\core\management\__init__.py", line 49, in load_command_class
    return module.Command()
           ^^^^^^^^^^^^^^^^
  File "d:\Programming-stuff\PythonProjects\notification\.venv\Lib\site-packages\django\core\management\base.py", line 284, in __init__
    raise TypeError("requires_system_checks must be a list or tuple.")
TypeError: requires_system_checks must be a list or tuple.

(versions:Python 3.12.0, Django 5.0.1, djangogrpcframework 0.2.1, grpcio-tools 1.60.0, grpcio 1.60.0)

I've already tried to update django-extensions, but didn't resolve the issue. I also tried to use alternative ways like using "py services.py" to run my grpc server directly but it came up with troubles as well (like not loading apps, and it's not the only one for sure!). any help will be appreciated <3

2

There are 2 answers

1
PTomasz On BEST ANSWER

Starting from Django 4.1 you cannot use boolean value as requires_system_checks in commands Django 4.1 Changelog and this package is using it in the grpcrunserver command in the 0.2.1 version which is also newest.

Downgrade Django to 4.1 and it should start working

0
The Homeless Coder On

I was having hell getting django-scheduler to work because part of the install process requires using bower. After reading I learned that to install bower dependencies, Django uses grpc server. So I ran into the exact same error.

Here is how I fixed it with credit to Ellnamin who commented on the other answer.

I opened base.py from following the errors path which looks like this--> C:Example\drive\user\project\Lib\site-packages\django\core\management\base.py

Then traced the error to line 284

The code looks like this:

def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False):
    self.stdout = OutputWrapper(stdout or sys.stdout)
    self.stderr = OutputWrapper(stderr or sys.stderr)
    if no_color and force_color:
        raise CommandError("'no_color' and 'force_color' can't be used together.")
    if no_color:
        self.style = no_style()
    else:
        self.style = color_style(force_color)
        self.stderr.style_func = self.style.ERROR
    if (
        not isinstance(self.requires_system_checks, (list, tuple))
        and self.requires_system_checks != ALL_CHECKS
    ):
        raise TypeError("requires_system_checks must be a list or tuple.")

I replaced

        raise TypeError("requires_system_checks must be a list or tuple.")

with

return

then ran my command to install dependencies again. Like magic it worked and I put the error back in because. You know, I'm scared.