CiviWiki / OpenCiviWiki

Building a Better Democracy for the Internet Age
https://civi.wiki
Other
587 stars 346 forks source link

Following contributing guide, migration step failing #1455

Open bigbuckalex opened 1 year ago

bigbuckalex commented 1 year ago

Description

I am following the contributing guide and I am getting this error message on the "Run migrations" step:

AttributeError: <asgiref.local.Local object at 0x7fd729a86e60> object has no attribute 'default'

What should have happened?

No response

What browser(s) are you seeing the problem on?

Not applicable

Further details

Full error message:

Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/utils/connection.py", line 58, in __getitem__
    return getattr(self._connections, alias)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/asgiref/local.py", line 105, in __getattr__
    raise AttributeError(f"{self!r} object has no attribute {key!r}")
AttributeError: <asgiref.local.Local object at 0x7fd729a86e60> object has no attribute 'default'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/GitHub/OpenCiviWiki/project/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
    django.setup()
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/apps/config.py", line 269, in import_models
    self.models_module = import_module(models_module_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 "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/db/models/base.py", line 141, in __new__
    new_class.add_to_class("_meta", Options(meta, app_label))
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/db/models/base.py", line 369, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/db/models/options.py", line 231, in contribute_to_class
    self.db_table, connection.ops.max_name_length()
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/utils/connection.py", line 60, in __getitem__
    if alias not in self.settings:
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/utils/connection.py", line 45, in settings
    self._settings = self.configure_settings(self._settings)
  File "/home/alex/.cache/pypoetry/virtualenvs/openciviwiki-vDri1UYP-py3.10/lib/python3.10/site-packages/django/db/utils.py", line 160, in configure_settings
    conn.setdefault("ATOMIC_REQUESTS", False)
AttributeError: 'str' object has no attribute 'setdefault'
brylie commented 1 year ago

There was an error in the installation guide that may have led to the above error.

Make sure you run poetry install from the repository root directory before changing the guide into the project/ subdirectory.

The migrations worked for me when I attempted them just now.

bigbuckalex commented 1 year ago

I've tried deleting and re-cloning the repo and I still get the same error. Here is a video of the process, am I doing anything wrong?

https://user-images.githubusercontent.com/13971705/198401749-02b06836-abfc-4b39-ae0f-d5c4fdb2f850.mp4

brylie commented 1 year ago

Can you upload a video where it creates the initial Poetry virtual environment?

bigbuckalex commented 1 year ago

Is this what you mean? I deleted the poetry environment so poetry install would create a new virtual environment.

https://user-images.githubusercontent.com/13971705/198710073-ae82b925-eb95-4d47-bae1-2cb9cfa671cf.mp4

brylie commented 1 year ago

@gorkemarslan are you able to spot anything that might be causing this bug?

gorkemarslan commented 1 year ago

@bigbuckalex, what operating system are you using?

As far as I understand, the Django framework cannot connect your local database because it cannot validate the database configs.

Can you try to replace the database configs in your settings.py file

https://github.com/CiviWiki/OpenCiviWiki/blob/549cd035ca43a63a1dc6b7e2f79154b80a1a9a61/project/core/settings.py#L118-L130

with the default one:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
bigbuckalex commented 1 year ago

@gorkemarslan I am using Pop!_OS 22.04

Replacing the database configs allowed me to run the migrations. Thank you!