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

Propose to disable system checks for generateproto, eliminating the need for a database connection. #337

Open
nohzafk opened this issue Jan 10, 2025 · 3 comments

Comments

@nohzafk
Copy link
Contributor

nohzafk commented Jan 10, 2025

Scenario

I want to generate protobuf using python manage.py generateproto command using a docker image

docker run --rm -v '.:/code' --entrypoint 'python'  <image_name> manage.py generateproto --project "server.settings"

It will attempt to connect to the database, as this is the default behavior of the Django command. An section of error log is attached below.

To my understanding, generating the protobuf files doesn't require actual database connection, add a --skip-checks to the command and it will work

docker run --rm -v '.:/code' --entrypoint 'python'  <image_name> manage.py generateproto --project "server.settings" --skip-checks

Proposal

Maybe we should disable the system checks at the generateproto command like this

class Command(BaseCommand):
    help = "Generates proto."
    # disable system checks and migration checks
    requires_system_checks = []
    requires_migrations_checks = []

Or document the usage of generateproto --skip-checks for skipping database connection

What do you think?

Error log

...
Traceback (most recent call last):
  File "/code/manage.py", line 30, in <module>
    main()
  File "/code/manage.py", line 26, in main
    management.execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.12/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.12/site-packages/django/core/management/base.py", line 453, in execute
    self.check()
  File "/usr/local/lib/python3.12/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ...

django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
@AMontagu
Copy link
Collaborator

Hello @nohzafk

I understand the need. I am afraid that disabling all system check before runing the command may lead other developers to false issue when using generateproto commands (eg: just change some code that make a check crash but want to generate the proto before runing the server)

Also --skip-checks sound perfect for that. I don't see any reason to not use it if needed.

Do you feel to create a PR with this documented ?

@nohzafk
Copy link
Contributor Author

nohzafk commented Jan 13, 2025

Yes, I will create a PR to document this usage. This will also be a good opportunity for me to learn how to enhance the documentation.

Where do you think we should put this information?

@AMontagu
Copy link
Collaborator

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

2 participants