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

RuntimeError: super(): empty __class__ cell #93

Closed
mskoenz opened this issue Nov 14, 2023 · 3 comments
Closed

RuntimeError: super(): empty __class__ cell #93

mskoenz opened this issue Nov 14, 2023 · 3 comments

Comments

@mskoenz
Copy link

mskoenz commented Nov 14, 2023

First off, thx for the cool package:

I'm mostly noting this here in case others encounter the same issue.

Calling super configure fails in AppConf subclasses:

How to reproduce:

mktmpenv # assuming virtualenvwrapper is installed
python --version
# Python 3.10.13
pip install django==4.2.7 django-appconf==1.0.5 # these are the current versions at time of writing
mkdir test
cd test
django-admin startproject demo
cd demo
./manage.py startapp app
  • add app to INSTALLED_APPS in demo/settings.py
  • add this at the end of app/apps.py
from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = "two"
    
    def configure(self):
        print("before fail")
        return super().configure()
  • now run the server with ./manage.py runserver
  • it fails with:
mskoenz:demo$ ./manage.py runserver
before fail
before fail
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/core/management/__init__.py", line 394, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/django/apps/config.py", line 123, in create
    mod = import_module(mod_path)
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/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 "/Users/mskoenz/programming/demo/app/apps.py", line 10, in <module>
    class MyAppConf(AppConf):
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/appconf/base.py", line 73, in __new__
    new_class._configure()
  File "/Users/mskoenz/.virtualenvs/tmp-7c6bbf99066cd53/lib/python3.10/site-packages/appconf/base.py", line 104, in _configure
    cls._meta.configured_data = obj.configure()
  File "/Users/mskoenz/programming/demo/app/apps.py", line 16, in configure
    return super().configure()
RuntimeError: super(): empty __class__ cell
  • if you comment the def configure(self): function and run ./manage.py runserver, it works (for me):
mskoenz:demo$ ./manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
November 14, 2023 - 06:23:11
Django version 4.2.7, using settings 'demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
@mskoenz
Copy link
Author

mskoenz commented Nov 14, 2023

We are using the following workaround after checking the code:

instead of:

from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = "two"
    
    def configure(self):
        conf =  super().configure()
        # modify conf
        return conf

we do:

from appconf import AppConf

class MyAppConf(AppConf):
    SETTING_1 = "one"
    SETTING_2 = "two"
    
    def configure(self):
        conf =  self.configured_data
        # modify conf
        return conf

@carltongibson
Copy link
Contributor

That's a nice example. I'm not expecting super() to work prior to the class definition completing so not sure there's much to say. 🤔

@carltongibson
Copy link
Contributor

Closing as not really actionable. Thanks for the report.

@carltongibson carltongibson closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
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