jneight / django-db-geventpool

Another DB pool using gevent
Apache License 2.0
167 stars 29 forks source link

ImportError: cannot import name 'DatabaseWrapperMixin' from 'django_db_geventpool.backends.postgresql_psycopg2.base #86

Closed gustahrodrigues closed 3 weeks ago

gustahrodrigues commented 2 months ago

Description:

Unable to start django-db-geventpool==4.0.5 due to ImportError: cannot import name 'DatabaseWrapperMixin' from 'django_db_geventpool.backends.postgresql_psycopg2.base

Steps to reproduce:

  1. Bootstrap a new Django project using Docker sample template
  2. Replace docker postgres image to postgis/postgis at docker-compose.yaml
  3. Add gdal-bin into Dockerfile
  4. Add django-db-geventpool==4.0.5 into requirements-txt
  5. Replace db engine to 'ENGINE': 'django_db_geventpool.backends.postgis'
  6. Start the project docker compose up

Observed result:

web-1  | Watching for file changes with StatReloader
web-1  | Exception in thread django-main-thread:
web-1  | Traceback (most recent call last):
web-1  |   File "/usr/local/lib/python3.12/site-packages/django_db_geventpool/backends/postgis/base.py", line 6, in <module>
web-1  |     import psycopg  # noqa
web-1  |     ^^^^^^^^^^^^^^
web-1  | ModuleNotFoundError: No module named 'psycopg'
web-1  |
web-1  | During handling of the above exception, another exception occurred:
web-1  |
web-1  | Traceback (most recent call last):
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/utils.py", line 111, in load_backend
web-1  |     return import_module('%s.base' % backend_name)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
web-1  |     return _bootstrap._gcd_import(name[level:], package, level)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
web-1  |   File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
web-1  |   File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
web-1  |   File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
web-1  |   File "<frozen importlib._bootstrap_external>", line 995, in exec_module
web-1  |   File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
web-1  |   File "/usr/local/lib/python3.12/site-packages/django_db_geventpool/backends/postgis/base.py", line 10, in <module>
web-1  |     from ..postgresql_psycopg2.base import DatabaseWrapperMixin
web-1  | ImportError: cannot import name 'DatabaseWrapperMixin' from 'django_db_geventpool.backends.postgresql_psycopg2.base' (/usr/local/lib/python3.12/site-packages/django_db_geventpool/backends/postgresql_psycopg2/base.py). Did you mean: 'DatabaseWrapper'?
web-1  |
web-1  | The above exception was the direct cause of the following exception:
web-1  |
web-1  | Traceback (most recent call last):
web-1  |   File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
web-1  |     self.run()
web-1  |   File "/usr/local/lib/python3.12/threading.py", line 1010, in run
web-1  |     self._target(*self._args, **self._kwargs)
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper
web-1  |     fn(*args, **kwargs)
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
web-1  |     autoreload.raise_last_exception()
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
web-1  |     raise _exception[1]
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/core/management/__init__.py", line 375, in execute
web-1  |     autoreload.check_errors(django.setup)()
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper
web-1  |     fn(*args, **kwargs)
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
web-1  |     apps.populate(settings.INSTALLED_APPS)
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/apps/registry.py", line 114, in populate
web-1  |     app_config.import_models()
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/apps/config.py", line 301, in import_models
web-1  |     self.models_module = import_module(models_module_name)
web-1  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
web-1  |     return _bootstrap._gcd_import(name[level:], package, level)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
web-1  |   File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
web-1  |   File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
web-1  |   File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
web-1  |   File "<frozen importlib._bootstrap_external>", line 995, in exec_module
web-1  |   File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/contrib/auth/models.py", line 3, in <module>
web-1  |     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
web-1  |     class AbstractBaseUser(models.Model):
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/models/base.py", line 122, in __new__
web-1  |     new_class.add_to_class('_meta', Options(meta, app_label))
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/models/base.py", line 326, in add_to_class
web-1  |     value.contribute_to_class(cls, name)
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/models/options.py", line 207, in contribute_to_class
web-1  |     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
web-1  |                                                  ^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/utils/connection.py", line 15, in __getattr__
web-1  |     return getattr(self._connections[self._alias], item)
web-1  |                    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/utils/connection.py", line 62, in __getitem__
web-1  |     conn = self.create_connection(alias)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/utils.py", line 204, in create_connection
web-1  |     backend = load_backend(db['ENGINE'])
web-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.12/site-packages/django/db/utils.py", line 122, in load_backend
web-1  |     raise ImproperlyConfigured(
web-1  | django.core.exceptions.ImproperlyConfigured: 'django_db_geventpool.backends.postgis' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
web-1  |     'mysql', 'oracle', 'postgresql', 'sqlite3'

Expected result:

django_db_geventpool.backends.postgis should work as expected.

Workaround

Downgrade to the version django-db-geventpool<=4.0.2

fdemmer commented 2 months ago

I opened https://github.com/jneight/django-db-geventpool/pull/85 to fix this. Can you maybe try and confirm it works for you?