sot / kadi

Chandra commands and events
https://sot.github.io/kadi
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Cannot run local server since #202 #206

Closed taldcroft closed 2 years ago

taldcroft commented 2 years ago

202 seems to break the basic local server testing functionality:

(ska3) ➜  kadi git:(master) ./manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/aldcroft/git/kadi/kadi/events/__init__.py", line 59, in <module>
    django.setup()
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/aldcroft/miniconda3/envs/ska3/lib/python3.8/site-packages/django/apps/registry.py", line 83, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
javierggt commented 2 years ago

One possibility could be to replace this statement

if 'manvrs' not in locals():

by this one:

from django.conf import settings
from django.utils.functional import empty
if settings._wrapped is empty:

I have not tested the gist from #201 yet, but I think it would work and it does not break the local server functionality.

We could make this change and also add an issue/PR in django to add a method to django.utils.functional.LazyObject that wraps the functionality. Something like:

    def is_set(self):
        return self._wrapped is not empty

This would be exactly the same thing, but at least it would be part of the public interface of the class, and perhaps it helps in keeping it working in future versions.

javierggt commented 2 years ago

actually, that method I proposed last does not work. It causes the same error, because LazyObject.__getattr__ calls self._setup(). I still don't know how this ends up causing that specific error.

javierggt commented 2 years ago

I just checked that the first solution I proposed works. Now the question is whether we want to go with it. I am creating a PR for that.