django-postgrespool2 icon indicating copy to clipboard operation
django-postgrespool2 copied to clipboard

Compatibility with SQLAlchemy 2.0.0

Open sohamM97 opened this issue 2 years ago • 2 comments

SQLAlchemy released version 2.0.0 on January 27, 2023, but django-postgrespool2 is not compatible with that yet. When I install django-postgrespool2 on a fresh environment, it installs SQLAlchemy 2.0.0 by default, which throws the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/django_postgrespool2/base.py", line 25, in <module>
    from sqlalchemy.pool import manage
ImportError: cannot import name 'manage' from 'sqlalchemy.pool' (/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/aistudio/manage.py", line 21, in <module>
    main()
  File "/opt/aistudio/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/options.py", line 207, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 122, in load_backend
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django_postgrespool2' 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:
    'mysql', 'oracle', 'postgresql', 'sqlite3'

This issue vanished when I installed SQLAlchemy 1.4.46 manually.

Please make django-postgrespool2 compatible with SQLAlchemy 2.0.0, or pin down the latest compatible version (1.4.46) as a dependency.

sohamM97 avatar Jan 27 '23 12:01 sohamM97

this is still happening with django-postgrespool2-2.0.5 and sqlalchemy-2.0.8. It doesn't pin the sqlalchemy version

tonyyu2009 avatar Apr 05 '23 22:04 tonyyu2009

Safety checker detects a vulnurability in slqalchemy==1.4.50. Authors have fixed it in 2.0+ but don't want to fix it in 1.4+. It seems the best way is to make django-postgrespool2 compatible with SQLAlchemy 2.0.0.

salykin avatar Nov 10 '23 16:11 salykin