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

Constance CLI does not work properly without django admin #498

Closed
Alirezaja1384 opened this issue Sep 17, 2022 · 3 comments · Fixed by #506
Closed

Constance CLI does not work properly without django admin #498

Alirezaja1384 opened this issue Sep 17, 2022 · 3 comments · Fixed by #506

Comments

@Alirezaja1384
Copy link

Describe the problem

It seems disabling django admin's app breaks the constance CLI. As I noticed constance/management/commands/constance.py imports ConstanceForm and get_values from admin configuration. The problem is admin.py tries to register the constance's config class and since the admin app is not present in INSTALLED_APPS django throws a LookupError.

I think splitting ConstanceForm and get_values to a separate module (like forms.py) and importing them directly from that module can easily fix the problem.

Steps to reproduce

  1. Remove django.contrib.admin from INSTALLED_APPS (And its URL pattern)
  2. Run python manage.py constance --help

System configuration

  • Django version: 4.0.7
  • Python version: 3.10.7
  • Django-Constance version: 2.9.1
@syre
Copy link
Contributor

syre commented Dec 1, 2022

I am running into the same thing, this is the error we are getting when trying to run python manage.py constance list for example:

Traceback (most recent call last):
  File "/venv/lib/python3.10/site-packages/django/apps/registry.py", line 156, in get_app_config
    return self.app_configs[app_label]
KeyError: 'admin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/dashboard/manage.py", line 22, in <module>
    main()
  File "/usr/src/dashboard/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/venv/lib/python3.10/site-packages/constance/management/commands/constance.py", line 10, in <module>
    from ...admin import ConstanceForm, get_values
  File "/venv/lib/python3.10/site-packages/constance/admin.py", line 366, in <module>
    admin.site.register([Config], ConstanceAdmin)
  File "/venv/lib/python3.10/site-packages/django/utils/functional.py", line 246, in inner
    self._setup()
  File "/venv/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 561, in _setup
    AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
  File "/venv/lib/python3.10/site-packages/django/apps/registry.py", line 163, in get_app_config
    raise LookupError(message)
LookupError: No installed app with label 'admin'.

@camilonova
Copy link
Member

@syre @Alirezaja1384 please confirm if this issue was resolved by installing the packed from the main branch

@Alirezaja1384
Copy link
Author

@camilonova I just tested it. It works completely fine. Thank you.

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

Successfully merging a pull request may close this issue.

3 participants