Coder Social home page Coder Social logo

altairbow / django-db-connection-pool Goto Github PK

View Code? Open in Web Editor NEW
168.0 4.0 20.0 149 KB

Database connection pool component library for Django

Home Page: https://pypi.python.org/pypi/django-db-connection-pool/

License: MIT License

Python 100.00%
django database pool pooling database-pool database-pooling jdbc postgresql mysql postgres

django-db-connection-pool's Introduction

django-db-connection-pool

⭐ If this project is helpful to you, please light up the star, Thank you😄

MySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django, Be based on SQLAlchemy. Works fine in multiprocessing and multithreading django project.

Quickstart

Installation

Install with pip with all engines:

$ pip install django-db-connection-pool[all]

or select specific engines:

$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]

or one of mysql,oracle,postgresql,jdbc

$ pip install django-db-connection-pool[oracle]

Update settings.DATABASES

MySQL

change django.db.backends.mysql to dj_db_conn_pool.backends.mysql:

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.mysql'
    }
}

Oracle

change django.db.backends.oracle to dj_db_conn_pool.backends.oracle:

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.oracle'
    }
}

PostgreSQL

change django.db.backends.postgresql to dj_db_conn_pool.backends.postgresql:

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.postgresql'
    }
}

Pool options(optional)

you can provide additional options to pass to SQLAlchemy's pool creation, key's name is POOL_OPTIONS:

DATABASES = {
    'default': {
        'POOL_OPTIONS': {
            'POOL_SIZE': 10,
            'MAX_OVERFLOW': 10,
            'RECYCLE': 24 * 60 * 60
        }
    }
}

django-db-connection-pool has more configuration options here: PoolContainer.pool_default_params

Here's the explanation of these options(from SQLAlchemy's Doc):

  • pool_size: The size of the pool to be maintained, defaults to 5. This is the largest number of connections that will be kept persistently in the pool. Note that the pool begins with no connections; once this number of connections is requested, that number of connections will remain. pool_size can be set to 0 to indicate no size limit; to disable pooling, use a :class:~sqlalchemy.pool.NullPool instead.

  • max_overflow: The maximum overflow size of the pool. When the number of checked-out connections reaches the size set in pool_size, additional connections will be returned up to this limit. When those additional connections are returned to the pool, they are disconnected and discarded. It follows then that the total number of simultaneous connections the pool will allow is pool_size + max_overflow, and the total number of "sleeping" connections the pool will allow is pool_size. max_overflow can be set to -1 to indicate no overflow limit; no limit will be placed on the total number of concurrent connections. Defaults to 10.

  • recycle: If set to a value other than -1, number of seconds between connection recycling, which means upon checkout, if this timeout is surpassed the connection will be closed and replaced with a newly opened connection. Defaults to -1.

Or, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:

import dj_db_conn_pool

dj_db_conn_pool.setup(pool_size=100, max_overflow=50)

multiprocessing environment

In a multiprocessing environment, such as uWSGI, each process will have its own dj_db_conn_pool.core:pool_container object, It means that each process has an independent connection pool, for example: The POOL_OPTIONS configuration of database db1 is{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }, If uWSGI starts 8 worker processes, then the total connection pool size of db1 is 8 * 10, The maximum number of connections will not exceed 8 * 10 + 8 * 20

JDBC

Thanks to JPype, django-db-connection-pool can connect to database by jdbc

Usage

Set Java runtime environment

export JAVA_HOME=$PATH_TO_JRE;
export CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR

Update settings.DATABASES

Oracle

change django.db.backends.oracle to dj_db_conn_pool.backends.jdbc.oracle:

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.jdbc.oracle'
    }
}
OceanBase

use dj_db_conn_pool.backends.jdbc.oceanbase:

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.jdbc.oceanbase'
    }
}

Performing raw SQL queries

Just like django's built-in backends, all JDBC backends support named parameters in raw SQL queries, you can execute raw sql queries like this:

from django.db import connections

with connections["default"].cursor() as cursor:
    cursor.execute('select name, phone from users where name = %(name)s', params={"name": "Altair"})
    result = cursor.fetchall()

Acknowledgments

  • Thanks to all friends who provided PR and suggestions !
  • Thanks to JetBrains for providing development tools for django-db-connection-pool !

django-db-connection-pool's People

Contributors

alexander-jacob avatar altairbow avatar grippy avatar jairhenrique avatar kevin-kessler avatar kkxue avatar rkojedzinszky avatar scottgigante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-db-connection-pool's Issues

Install: pg_config executable not found.

I'm using google's Cloud SQL for production DB and hitting connection limits.

When I try

pip install "django-db-connection-pool[postgresql]"

I get the following Error: pg_config executable not found. (see Full Traceback below)

Q1) I don't run/configure postgres locally, is this a blocker?
Q2) do I need to add anything to INSTALLED_APPS in settings.py or just DATABASES

Thanks!

Env

Python 3.8.12 +

psycopg2-binary           2.9.3                    pypi_0    pypi
django                    4.0.4                    pypi_0    pypi
django-cors-headers       3.12.0                   pypi_0    pypi
django-cursor-pagination  0.2.0                    pypi_0    pypi
django-environ            0.8.1                    pypi_0    pypi
django-sslserver          0.22                     pypi_0    pypi
djangorestframework       3.13.1                   pypi_0    pypi

Full Traceback

``` WARNING: Discarding https://files.pythonhosted.org/packages/6c/79/6df8af2405e2aa60732c47757453fc7fa4af5c90a1796b3392ef892d3a52/psycopg2-2.9.tar.gz#sha256=b12073fdf2002e828e5921be2c39ff9c6eab361c5c0bd6c529619fc23677accc (from https://pypi.org/simple/psycopg2/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. Using cached psycopg2-2.8.6.tar.gz (383 kB) ERROR: Command errored out with exit status 1: command: /home/sam/.conda/envs/character-20220124-sam/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i7o40hoo/psycopg2_b4149a9e81ea4377befddde281a9336d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i7o40hoo/psycopg2_b4149a9e81ea4377befddde281a9336d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-qsylyfe8 cwd: /tmp/pip-install-i7o40hoo/psycopg2_b4149a9e81ea4377befddde281a9336d/ Complete output (25 lines): running egg_info creating /tmp/pip-pip-egg-info-qsylyfe8/psycopg2.egg-info writing /tmp/pip-pip-egg-info-qsylyfe8/psycopg2.egg-info/PKG-INFO writing dependency_links to /tmp/pip-pip-egg-info-qsylyfe8/psycopg2.egg-info/dependency_links.txt writing top-level names to /tmp/pip-pip-egg-info-qsylyfe8/psycopg2.egg-info/top_level.txt writing manifest file '/tmp/pip-pip-egg-info-qsylyfe8/psycopg2.egg-info/SOURCES.txt' /home/sam/.local/lib/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead. warnings.warn(msg, warning_class)
Error: pg_config executable not found.

pg_config is required to build psycopg2 from source.  Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.

For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).

----------------------------------------

WARNING: Discarding https://files.pythonhosted.org/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz#sha256=fb23f6c71107c37fd667cb4ea363ddeb936b348bbd6449278eb92c189699f543 (from https://pypi.org/simple/psycopg2/) (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Collecting django-db-connection-pool[postgresql]
Using cached django-db-connection-pool-1.1.0.tar.gz (11 kB)
Using cached django-db-connection-pool-1.0.7.tar.gz (7.0 kB)
Using cached django-db-connection-pool-1.0.6.tar.gz (7.1 kB)
Using cached django-db-connection-pool-1.0.5.tar.gz (6.4 kB)
WARNING: django-db-connection-pool 1.0.5 does not provide the extra 'postgresql'
Requirement already satisfied: PyMySQL>=0.9.3 in /home/sam/.local/lib/python3.8/site-packages (from django-db-connection-pool[postgresql]) (1.0.2)
Requirement already satisfied: cx-Oracle>=6.4.1 in /home/sam/.local/lib/python3.8/site-packages (from django-db-connection-pool[postgresql]) (8.3.0)
Using cached django_db_connection_pool-1.0.2-py3-none-any.whl
WARNING: django-db-connection-pool 1.0.2 does not provide the extra 'postgresql'
Requirement already satisfied: greenlet!=0.4.17 in /home/sam/.local/lib/python3.8/site-packages (from SQLAlchemy>=1.4.24->django-db-connection-pool[postgresql]) (1.1.2)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/sam/.local/lib/python3.8/site-packages (from Django->django-db-connection-pool[postgresql]) (3.5.2)
Requirement already satisfied: sqlparse>=0.2.2 in /home/sam/.local/lib/python3.8/site-packages (from Django->django-db-connection-pool[postgresql]) (0.4.2)
Requirement already satisfied: backports.zoneinfo in /home/sam/.local/lib/python3.8/site-packages (from Django->django-db-connection-pool[postgresql]) (0.2.1)
WARNING: Ignoring invalid distribution -rpcio (/home/sam/.local/lib/python3.8/site-packages)
Installing collected packages: django-db-connection-pool
^CERROR: Operation cancelled by user
WARNING: Ignoring invalid distribution -rpcio (/home/sam/.local/lib/python3.8/site-packages)
WARNING: Ignoring invalid distribution -rpcio (/home/sam/.local/lib/python3.8/site-packages)
WARNING: Ignoring invalid distribution -rpcio (/home/sam/.local/lib/python3.8/site-packages)

</details>


Describe the bug
A clear and concise description of what the bug is.

Environment

  • Python Version:
  • Django Version:

Traceback
Post traceback here.

The _ConnectionFairy.connection attribute is deprecated

Describe the bug
With sqlalchemy 2.0+ a deprecation warning is raised.
driver_connection has been introduced with sqlalchemy 1.4.24 and connection has been deprecated in favor of this with sqlachemy 2.
Since 1.4.24 is exactly the minimum version required by django-db-connection-pool I hope that the fix can be easily introduced.

Environment

  • Python Version: 3.10.8
  • Django Version: 4.1.7
  • SQLAlchemy Version: 2.0.4

Traceback

  /usr/local/lib/python3.10/site-packages/dj_db_conn_pool/core/mixins.py:104: 
      SADeprecationWarning: The _ConnectionFairy.connection attribute is deprecated;
            please use 'driver_connection' (deprecated since: 2.0)
    self.alias, conn.connection)

django startup error (environment: python(v3.8) django(v4.0) pymysql(v1.0.2) django-db-connection-pool(v1.0.7))

File "...\lib\site-packages\django\db\utils.py", line 122, in load_backend
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'dj_db_conn_pool.backends.mysql' 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'

PostgreSQL backend support

Hello,do you have any plan to support PostgreSQL backend?actually,I will give you a PR soon about it.

Django run error

django.core.exceptions.ImproperlyConfigured: 'dj_db_conn_pool.backends.oracle' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: No module named 'dj_db_conn_pool'

Save not committing when using pool

Tried out connetion pool and it worked great for read queries. However, when saving, the queries doesn't seem to commit and hence not able to write anything to db.
Not 100% sure its the commit not working, assuming so because there were no errors in the output.

Config -

'default': {
'ENGINE': 'dj_db_conn_pool.backends.oracle',
'NAME': 'xxx',
'USER': 'xxxx',
'PASSWORD': 'xxx',
'CONN_MAX_AGE': 250, # For ATP, the timeout period at db end seen to be 5 mins.
'POOL_OPTIONS': {
'POOL_SIZE': 5,
'MAX_OVERFLOW': 5,
'autocommit': True,
},
}

New release?

First of all, a big THANK YOU for this wonderful project.

The last release was from January last year and many nice improvements have been made since then. Maybe it is time for a new release? Would be much appreciated!

Kind regards,
Rutger

您好,麻烦请问下这个Django链接池的包怎么设置日志等级啊?

您好:
首先感谢您的劳动和分享精神。作为一个刚入门或者说还没入门的小白,用您的Django链接池的包确实解决了实际问题。

其次,想请问您,这个包的日志等级怎么设置的?我Django项目的日志设置的是debug。用了您写的这个链接池的包后,日志里会生成如下日志:
2020-11-15 17:33:21,750 INFO sqlalchemy.pool.impl.QueuePool Connection <pymysql.connections.Connection object at 0x7f7d6ec319e8> exceeded timeout; recycling

而且还挺多的。虽然不影响使用,但每次看日志的时候还是会影响查看效率。想说咱这个链接池的包怎么能只输出warning和debug级别的日志。

感谢您,望回复。

Django doesnt respect the pool configuration when using "gevent" class

Issue : After setting all the pre-requisites with below configuration

'POOL_OPTIONS' : {
'POOL_SIZE': 10,
'MAX_OVERFLOW': 10,
'RECYCLE': 24 * 60 * 60
}

If i run below command

gunicorn your_project_name.wsgi:application -k gevent -w 4

My assumptions is it will use pool_size which I have set to 10. But I see DB connections going high based on the number of concurrent request.

dj_db_conn_pool.backends.postgis problem with python manage.py CMD

When i use python manage.py makemigrations or python manage.py runserver i have this error:

Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 136, in inner_run
self.check_migrations()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/core/management/base.py", line 574, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in init
self.loader = MigrationLoader(self.connection)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/migrations/loader.py", line 58, in init
self.build_graph()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 330, in cursor
return self._cursor()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 306, in _cursor
self.ensure_connection()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 272, in connect
self.init_connection_state()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 310, in init_connection_state
super().init_connection_state()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 239, in init_connection_state
self.check_database_version_supported()
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/base/base.py", line 210, in check_database_version_supported
and self.get_database_version() < self.features.minimum_database_version
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 188, in get_database_version
return divmod(self.pg_version, 10000)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/utils/functional.py", line 57, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/dev/miniconda3/envs/ENV_PROJECTS/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 438, in pg_version
return self.connection.info.server_version
AttributeError: 'dict' object has no attribute 'server_version'

I use

  • Python Version: 3.8
  • Django Version: 4.2

ad ENGINE in settings.py is this:

DATABASES = {
"default": {
"ENGINE": "dj_db_conn_pool.backends.postgis",

Changes don't get committed to database when using pool.

I can see that there is a closed issue with similar problem, but no resolution was found. So I will dare to open a new one.

I'm running Django 3.1.5 app and postgres db on Azure, and experiencing 1,5-2 second latency on all views that require database connection. This particular package was suggested by Microsoft support, and it does indeed reduce response time down to 150-200 ms, which is great. There is no problem with retrieving data from the db, however saving data is very inconsistent across the app, but still looks consistent for a given view, meaning that some views consistently succeed with saving data, while other views consistently fail...

I have tried to add AUTOCOMIT=True to settings config, but it didn't help

Any suggestions on how to fix the problem , or where to start looking?

2006, 'MySQL server has gone away' 2013, 'Lost connection to MySQL server during query

Describe the bug
I have some scheduled tasks, get the connection operation database through the connection pool, and perform the task operation database again to report MySQL 2006 and MySQL2013 error.

my setting:
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.mysql',
'NAME': SQL_DB,
'USER': SQL_USER,
'HOST': SQL_HOST,
'POOL_OPTIONS': {
'POOL_SIZE': 5,
'MAX_OVERFLOW': -1,
'RECYCLE': 60
}
},
}

Environment

  • Python Version: 3.7
  • Django Version: 2.2.4

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

Traceback (most recent call last):
File "", line 1, in
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 263, in repr
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 269, in len
self._fetch_all()
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 53, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (2006, 'MySQL server has gone away')

Traceback (most recent call last):
File "", line 1, in
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 263, in repr
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 269, in len
self._fetch_all()
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/query.py", line 53, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/Users/admin/Desktop/code/virtualenv/mbot/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (2013, 'Lost connection to MySQL server during query')

ORA-01036: illegal variable name/number

Describe the bug
Just followed the guide, restarted app, refresh the page and it raises the error: ORA-01036: illegal variable name/number

Environment

  • Python Version: 3.10
  • Django Version: 4.2.1

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

Traceback (most recent call last):
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/admin/options.py", line 688, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
response = view_func(request, *args, **kwargs)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 230, in inner
if not self.has_permission(request):
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 203, in has_permission
return request.user.is_active and request.user.is_staff
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/utils/functional.py", line 266, in inner
self._setup()
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/utils/functional.py", line 419, in _setup
self._wrapped = self._setupfunc()
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 25, in
request.user = SimpleLazyObject(lambda: get_user(request))
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
request._cached_user = auth.get_user(request)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/auth/init.py", line 191, in get_user
user_id = _get_user_session_key(request)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/auth/init.py", line 60, in _get_user_session_key
return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 53, in getitem
return self._session[key]
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 192, in _get_session
self._session_cache = self.load()
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 42, in load
s = self._get_session_from_db()
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 32, in _get_session_from_db
return self.model.objects.get(
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/query.py", line 633, in get
num = len(clone)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/query.py", line 380, in len
self._fetch_all()
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/query.py", line 91, in iter
results = compiler.execute_sql(
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1560, in execute_sql
cursor.execute(sql, params)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "/var/www/django_sites/django_sites_venv/lib/python3.10/site-packages/dj_db_conn_pool/core/utils.py", line 38, in execute
return cursor.execute(query, parameters or [])
django.db.utils.DatabaseError: ORA-01036: illegal variable name/number

Thanks !!!

django run error.

django.core.exceptions.ImproperlyConfigured: 'dj_db_conn_pool.backends.mysql' isn't an available database backend or couldn't be imported. Check the above exception. To use on
e of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:

Re-try connect in case of (specific?) errors with new connection?

I am seeing sporadic errors when trying to get a new connection on Google Cloud Run with PostgreSQL, and wondered what you think about a patch to re-try in case of those when acquiring a new connection.

Those are OperationalErrors, e.g.:

connection to server at "10.171.0.32", port 5432 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

Traceback:

…
File "django/db/backends/base/base.py", line 260, in _cursor
    self.ensure_connection()
  File "django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "django/db/backends/base/base.py", line 243, in ensure_connection
    with self.wrap_database_errors:
  File "django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "django/db/backends/base/base.py", line 244, in ensure_connection
    self.connect()
  File "django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "django/db/backends/base/base.py", line 225, in connect
    self.connection = self.get_new_connection(conn_params)
  File "dj_db_conn_pool/core/mixins.py", line 76, in get_new_connection
    conn = db_pool.connect()
  File "sqlalchemy/pool/base.py", line 310, in connect
    return _ConnectionFairy._checkout(self)
  File "sqlalchemy/pool/base.py", line 868, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "sqlalchemy/pool/base.py", line 476, in checkout
    rec = pool._do_get()
  File "sqlalchemy/pool/impl.py", line 145, in _do_get
    with util.safe_reraise():
  File "sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "sqlalchemy/pool/impl.py", line 143, in _do_get
    return self._create_connection()
  File "sqlalchemy/pool/base.py", line 256, in _create_connection
    return _ConnectionRecord(self)
  File "sqlalchemy/pool/base.py", line 371, in __init__
    self.__connect()
  File "sqlalchemy/pool/base.py", line 665, in __connect
    with util.safe_reraise():
  File "sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "sqlalchemy/pool/base.py", line 661, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
  File "sqlalchemy/pool/base.py", line 241, in <lambda>
    return lambda crec: creator()
  File "dj_db_conn_pool/core/mixins.py", line 60, in <lambda>
    lambda: self._get_new_connection(conn_params),
  File "dj_db_conn_pool/core/mixins.py", line 15, in _get_new_connection
    return super(PooledDatabaseWrapperMixin, self).get_new_connection(conn_params)
  File "django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "django/db/backends/postgresql/base.py", line 203, in get_new_connection
    connection = Database.connect(**conn_params)
  File "__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)

Does not detects psycopg[binary]. Tries to install psycopg2[binary].

Describe the bug
I have moved from psycopg2[binary] to psycopg[binary] (Version 3.1.17 - Successor to psycopg2). But this package doesn't detects that. It has a fixed requirement of psycopg2 and therefore the installation fails.

django's backend
Switch to django's backend (django.db.backends.xxx), does the problem reproduce?
Can't test that as the installation fails.

Environment

  • Python Version: 3.10
  • Django Version: 4.2.7 & 4.2.9

Traceback
Post traceback here.
If you prefer to avoid building psycopg2 from source, please install the PyPI err: 'psycopg2-binary' package instead.
Screenshot 2024-01-26 at 9 02 41 AM

Optional: SQL and parameters
Post SQL and parameters here, Pay attention to hiding private information.
N/A

save does not committing when using pool

Thanks @altairbow , I have same problem.
I can not save correctly. the program looks ok without error but the table is not update when I check it on django admin. It works ok when I use (('ENGINE': 'django.db.backends.oracle')) with out the pool.

Python3.8.10 + django 3.2 + Oracle 18C

'default': {
'ENGINE': 'dj_db_conn_pool.backends.oracle',
'POOL_OPTIONS': {
'POOL_SIZE': 10,
'MAX_OVERFLOW': 10,
'RECYCLE': 24 * 60 * 60,
},
'AUTOCOMMIT': True,
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
}

Originally posted by @boscharun in #5 (comment)

django 连接oceanbase Mysql租户,make migrantions 失败,

Describe the bug
A clear and concise description of what the bug is.
大佬, 使用该包连接OB 的Mysql租户时,在 makemigrations 时出现错误如下:
应该如何解决,请求帮助万分感激。
manage.py@obtest > makemigrations
"C:\Program Files\JetBrains\PyCharm 2020.3.3\bin\runnerw64.exe" C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe "C:\Program Files\JetBrains\PyCharm 2020.3.3\plugins\python\helpers\pycharm\django_manage.py" makemigrations D:/obtest
Tracking file by folder pattern: migrations
D:\Program Files\Java\jdk1.8.0_351\jre\bin\server\jvm.dll
hell
Oracle
jdbc:oceanbase://192.168.1.161:2883/sre
Traceback (most recent call last):
File "PreparedStatement.java", line 1231, in com.alipay.oceanbase.jdbc.PreparedStatement.execute
File "PreparedStatement.java", line 1942, in com.alipay.oceanbase.jdbc.PreparedStatement.executeInternal
File "ConnectionImpl.java", line 2908, in com.alipay.oceanbase.jdbc.ConnectionImpl.execSQL
File "MysqlIO.java", line 3164, in com.alipay.oceanbase.jdbc.MysqlIO.sqlQueryDirect
File "MysqlIO.java", line 2998, in com.alipay.oceanbase.jdbc.MysqlIO.sendCommand
File "MysqlIO.java", line 4804, in com.alipay.oceanbase.jdbc.MysqlIO.checkErrorPacket
File "MysqlIO.java", line 4879, in com.alipay.oceanbase.jdbc.MysqlIO.checkErrorPacket
File "SQLError.java", line 1176, in com.alipay.oceanbase.jdbc.SQLError.createSQLException
File "Util.java", line 416, in com.alipay.oceanbase.jdbc.Util.getInstance
File "Util.java", line 439, in com.alipay.oceanbase.jdbc.Util.handleNewInstance
File "Constructor.java", line 423, in java.lang.reflect.Constructor.newInstance
File "DelegatingConstructorAccessorImpl.java", line 45, in sun.reflect.DelegatingConstructorAccessorImpl.newInstance
File "NativeConstructorAccessorImpl.java", line 62, in sun.reflect.NativeConstructorAccessorImpl.newInstance
File "NativeConstructorAccessorImpl.java", line -2, in sun.reflect.NativeConstructorAccessorImpl.newInstance0
Exception: Java Exception

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

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\jaydebeapi_init_.py", line 534, in execute
is_rs = self._prep.execute()
com.alipay.oceanbase.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: com.alipay.oceanbase.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'view_name' in 'field list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2020.3.3\plugins\python\helpers\pycharm\django_manage.py", line 52, in
run_command()
File "C:\Program Files\JetBrains\PyCharm 2020.3.3\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, 'main', True)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:/obtest\manage.py", line 22, in
main()
File "D:/obtest\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management_init
.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management_init
.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\loader.py", line 283, in check_consistent_history
applied = recorder.applied_migrations()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
if self.has_table():
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
return get_names(cursor)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\introspection.py", line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\oracle\introspection.py", line 64, in get_table_list
""")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 82, in execute
return self.cursor.execute(sql)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\dj_db_conn_pool\backends\jdbc\utils.py", line 39, in execute
self.cursor.cursor.execute(query, parameters)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\jaydebeapi_init
.py", line 536, in execute
handle_sql_exception()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\jaydebeapi_init
.py", line 165, in handle_sql_exception_jpype
reraise(exc_type, exc_info[1], exc_info[2])
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\jaydebeapi_init
.py", line 57, in reraise
raise value.with_traceback(tb)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\jaydebeapi_init
.py", line 534, in execute
is_rs = self._prep.execute()
jaydebeapi.DatabaseError: com.alipay.oceanbase.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'view_name' in 'field list'

Process finished with exit code 1

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

Environment

  • Python Version: 3.6
  • Django Version: 2.26
  • -Java-jdk:1.8

Traceback
Post traceback here.
1

Does it support pg8000?

Hi

I am curious whether this connection pool supports pg8000. SQalchemy 1.4 fully supports pg8000

Regards

ygl

SIGINT not closing connections with celery

When I send a sigint to my celery process using gevent, it appears that the pool connections stay open and the celery process hangs while waiting for all connections to close. How can I close all connections in the pool? I can put that in a worker shutdown hook.

I've tried using pool.dispose on the pools in pool_cotainer, but after reading sqlalchemy docs that appears to leave some connections open.

can't install neither by pip nor by tar pkg

install error
neither by pip nor by tar pkg
pip:
pip install django-db-connection-pool
tar pkg:
python setup.py install

error info:

Traceback (most recent call last):
  File "setup.py", line 16, in <module>
    long_description=open('README.md', encoding='UTF-8').read(),
TypeError: 'encoding' is an invalid keyword argument for this function

encoding issue

Traceback (most recent call last):
  File "D:/fproject/om-platform/manage.py", line 5, in <module>
    from model_index import tools
  File "D:\fproject\om-platform\model_index\tools.py", line 16, in <module>
    django.setup()
  File "D:\fproject\om-platform\venv\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\fproject\om-platform\venv\lib\site-packages\django\apps\registry.py", line 108, in populate
    app_config.import_models()
  File "D:\fproject\om-platform\venv\lib\site-packages\django\apps\config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:\fproject\om-platform\venv\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "D:\fproject\om-platform\venv\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\models\base.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\models\base.py", line 331, in add_to_class
    value.contribute_to_class(cls, name)
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "D:\fproject\om-platform\venv\lib\site-packages\django\db\utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:\fproject\om-platform\venv\lib\site-packages\dj_db_conn_pool\backends\__init__.py", line 8
SyntaxError: Non-ASCII character '\xe4' in file D:\fproject\om-platform\venv\lib\site-packages\dj_db_conn_pool\backends\__init__.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Test case run fails with the documented setup

After setting up the library, there's no issue with running the server but when it comes to running the test-cases I'm getting error for not being able to clean up database.

settings.py :

DATABASES = {
    'default': {
        'ENGINE': 'dj_db_conn_pool.backends.postgresql',
        'NAME': '<db_name>',
        'USER': '<username>',
        'PASSWORD': '<password>',
        'HOST': '127.0.0.1',
        'PORT': '5432',
        'CONN_MAX_AGE': None,
        'CONN_HEALTH_CHECKS': True,
        'TEST': {
            'NAME': 'test_db_2311',
            'SERIALIZE': False
        },
        'POOL_OPTIONS' : {
            'POOL_SIZE': 10,
            'MAX_OVERFLOW': 10,
            'RECYCLE': -1
        }
    }
}

Error found :

Ran 97 tests in 112.682s

OK
Destroying test database for alias 'default'...
/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/postgresql/base.py:301: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.ObjectInUse: database "test_db_2311" is being accessed by other users
DETAIL:  There is 1 other session using the database.


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

Traceback (most recent call last):
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 299, in _nodb_cursor
    yield cursor
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/base/creation.py", line 283, in _destroy_test_db
    cursor.execute("DROP DATABASE %s"
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
django.db.utils.OperationalError: database "test_db_2311" is being accessed by other users
DETAIL:  There is 1 other session using the database.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/core/management/commands/test.py", line 53, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django_nose/runner.py", line 308, in run_tests
    result = self.run_suite(nose_argv)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django_nose/runner.py", line 244, in run_suite
    nose.core.TestProgram(argv=nose_argv, exit=False,
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/unittest/main.py", line 101, in __init__
    self.runTests()
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/nose/core.py", line 207, in runTests
    result = self.testRunner.run(self.test)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/nose/core.py", line 66, in run
    result.printErrors()
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/nose/plugins/manager.py", line 99, in __call__
    return self.call(*arg, **kw)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/nose/plugins/manager.py", line 167, in simple
    result = meth(*arg, **kw)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django_nose/plugin.py", line 88, in finalize
    self.runner.teardown_databases(self.old_names)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django_nose/runner.py", line 496, in teardown_databases
    return super(NoseTestSuiteRunner, self).teardown_databases(
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/test/runner.py", line 645, in teardown_databases
    _teardown_databases(
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/test/utils.py", line 298, in teardown_databases
    connection.creation.destroy_test_db(old_name, verbosity, keepdb)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/base/creation.py", line 267, in destroy_test_db
    self._destroy_test_db(test_database_name, verbosity)
  File "/Users/<path_to_project>/venvm/lib/python3.8/site-packages/django/db/backends/base/creation.py", line 283, in _destroy_test_db
    cursor.execute("DROP DATABASE %s"
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/contextlib.py", line 162, in __exit__
    raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()

Django 4.2 incompatibility

Describe the bug

When upgrading to Django 4.2, I got an exception deep in Django where it tries to get the self.connection.server_version; which is an empty dict currently.

Where the self.connection is a <sqlalchemy.pool.base._ConnectionFairy> and if you do self.connection.connection.info.server_version it works fine!

The ConnectionFairy has an attribute name conflict as mentioned in this issue I found on sqlalchemy related to this, and a comment on that issue (sqlalchemy/sqlalchemy#4620 (comment)). Comment talks about simply assigning the .info to the .connection.info after establishing the connection to fix the problem.

If I do that (locally, with a cloned version of django-db-connection-pool), it seems to work. I could push up a PR for you to look at if you want.

Code that fixes issue (file: dj_db_conn_pool/backends/postgresql/base.py):

class DatabaseWrapper(PGDatabaseWrapperMixin, base.DatabaseWrapper):
    def get_new_connection(self, conn_params):
        connection = super().get_new_connection(conn_params)
        connection.info = connection.connection.info
        return connection

Exception:

AttributeError: 'dict' object has no attribute 'server_version'

Environment

  • Python Version: 3.9.14
  • Django Version: 4.2.1

Traceback

Traceback (most recent call last):
  File ".../site-packages/rest_framework/request.py", line 74, in wrap_attributeerrors
    yield
  File ".../site-packages/rest_framework/request.py", line 227, in user
    self._authenticate()
  File ".../site-packages/rest_framework/request.py", line 380, in _authenticate
    user_auth_tuple = authenticator.authenticate(self)
  File "auth.py", line 355, in authenticate
    user = User.objects.get(id=user_id)
  File ".../site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File ".../site-packages/django/db/models/query.py", line 633, in get
    num = len(clone)
  File ".../site-packages/django/db/models/query.py", line 380, in __len__
    self._fetch_all()
  File ".../site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File ".../site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File ".../site-packages/django/db/models/sql/compiler.py", line 1558, in execute_sql
    cursor = self.connection.cursor()
  File ".../site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File ".../site-packages/django/db/backends/base/base.py", line 330, in cursor
    return self._cursor()
  File ".../site-packages/django/db/backends/base/base.py", line 306, in _cursor
    self.ensure_connection()
  File ".../site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File ".../site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
    self.connect()
  File ".../site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File ".../site-packages/django/db/backends/base/base.py", line 272, in connect
    self.init_connection_state()
  File ".../site-packages/django/db/backends/postgresql/base.py", line 309, in init_connection_state
    super().init_connection_state()
  File ".../site-packages/django/db/backends/base/base.py", line 239, in init_connection_state
    self.check_database_version_supported()
  File ".../site-packages/django/db/backends/base/base.py", line 210, in check_database_version_supported
    and self.get_database_version() < self.features.minimum_database_version
  File ".../site-packages/django/db/backends/postgresql/base.py", line 188, in get_database_version
    return divmod(self.pg_version, 10000)
  File ".../site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File ".../site-packages/django/db/backends/postgresql/base.py", line 437, in pg_version
    return self.connection.info.server_version
AttributeError: 'dict' object has no attribute 'server_version'

MySQL server has gone away

We are trying to execute two tasks concurrently using celery with two different queues of rabbitmq,
one task execute successfully but second task will not succeeded , this will drop mysql connections.
if we try both functions without queuing, it will not give any error.

That means, if concurrent request is passed to mysql that loss mysql connections. for sequential execution it will works properly.

Please provide solution to overcome this isuue

TypeError during attempted rollback

During a loss of server connection due to timeout, the following error occurs. Not sure if this is actually a SQLAlchemy error or if it can be fixed in this library somehow.

Traceback (most recent call last):
File "/home/simernes/.local/lib/python3.6/site-packages/sqlalchemy/dialects/mysql/base.py", line 2318, in do_rollback
    dbapi_connection.rollback()
MySQLdb._exceptions.OperationalError: (2006, 'MySQL server has gone away')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/simernes/.local/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 693, in _finalize_fairy
    fairy._reset(pool)
File "/home/simernes/.local/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 880, in _reset
    pool._dialect.do_rollback(self)
File "/home/simernes/.local/lib/python3.6/site-packages/sqlalchemy/dialects/mysql/base.py", line 2320, in do_rollback
    if self.server_version_info < (12, 34, 56):
TypeError: '<' not supported between instances of 'NoneType' and 'tuple'

Why do we need psycopg2 ?

I am trying to install this library on ubantu , i am getting below error.

Using cached https://files.pythonhosted.org/packages/08/e8/fc93fe1b04e3135fdcf4508ab9fc73325725baf2f82cc6f083cd9fee698f/cx_Oracle-8.2.1-cp38-cp38-manylinux1_x86_64.whl
Collecting psycopg2>=2.8.6 (from django-db-connection-pool[all])
Using cached https://files.pythonhosted.org/packages/aa/8a/7c80e7e44fb1b4277e89bd9ca509aefdd4dd1b2c547c6f293afe9f7ffd04/psycopg2-2.9.1.tar.gz
ERROR: Command errored out with exit status 1:
command: /home/bflmfuser/venv383/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-pcp77yav/psycopg2/setup.py'"'"'; file='"'"'/tmp/pip-install-pcp77yav/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /tmp/pip-install-pcp77yav/psycopg2/
Complete output (23 lines):
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source.  Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.

For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).

I have psycopg2-binary installed on my server. still it is giving the error.

dj_db_conn_pool make migrations

Describe the bug
There is some problems about dj_db_conn_pool migrations. Some fields are missing.

Environment
Python3.8.10 + django 3.2 + Oracle 18C

Traceback
My model is :

 class Tbl_Terminal(models.Model):
   id = models.CharField(max_length=8, db_column='id', primary_key=True)
   merchant_id = models.ForeignKey(Tbl_Merchant, related_name="terminal_merchant", on_delete=models.PROTECT)
   type_id = models.ForeignKey(Tbl_Terminal_Type, related_name="terminal_type", on_delete=models.PROTECT)
   serial_no = models.CharField(null=True, max_length=15)
   status = models.IntegerField(choices=TerminalStatus.choices)
   nii = models.PositiveIntegerField(validators=[MaxValueValidator(999)])
   stan = models.PositiveIntegerField(validators=[MaxValueValidator(999999)])
   app_version =models.CharField(max_length=20,null=True,blank=True)
   logon_date = models.DateTimeField(auto_now_add=True,null=True)

After apply migrations, the field logon_date was not created

postgresl无法正常插入或更新数据库

DATABASES : 'ENGINE': 'dj_db_conn_pool.backends.postgresql',
django:3.1.2
Sqlalchemy:1.4.32
实例:
obj = CircleDepartmentModel.objects.get(id=13)
print(obj.dep_name) # 大研发
obj.dep_name = "1234"
obj.save()

结果:数据库表中dep_name没有更新

Got an error creating the test database: CREATE DATABASE cannot run inside a transaction block

After I installed django-db-connection-pool all my tests started to fail like this:

Creating test database for alias 'default'...
2020-12-30 11:03:04,219 dj_db_conn_pool.core.mixins DEBUG    __no_db__'s pool has been created, parameter: {'pre_ping': True, 'echo': True, 'timeout': None, 'recycle': 3600, 'pool_size': 30, 'max_overflow': 30}
2020-12-30 11:03:04,222 dj_db_conn_pool.core.mixins DEBUG    got __no_db__'s connection from its pool
Got an error creating the test database: CREATE DATABASE cannot run inside a transaction block

2020-12-30 11:03:04,223 dj_db_conn_pool.core.mixins DEBUG    release __no_db__'s connection to its pool
2020-12-30 11:03:04,224 dj_db_conn_pool.core.mixins DEBUG    release default's connection to its pool

Any idea?

OperationalError SSL SYSCALL error: EOF detected

Describe the bug
We are seeing a lot of the below errors after switching to django-db-connection-pool, before we never saw this issue.
OperationalError
SSL SYSCALL error: EOF detected

Environment

  • Python Version: 3.9.16
  • Django Version: 3.2.14

Traceback
django/db/backends/utils.py in _execute at line 84

    with self.db.wrap_database_errors:
        if params is None:
            # params default might be backend specific.
            return self.cursor.execute(sql)
        else:
            return self.cursor.execute(sql, params) <-- line number 84

1.2.3 is broken.

Describe the bug

after upgrade from 1.2.2 to 1.2.3 , running into:

'CursorWrapper' object is not iterable

Environment

  • Python Version: 3.9
  • Django Version: 3.2.7

Traceback
django/db/backends/utils.py in iter at line 30
System

    else:
        return cursor_attr
def __iter__(self):
    with self.db.wrap_database_errors:
        yield from self.cursor
def __enter__(self):
    return self
def __exit__(self, type, value, traceback):

django 3.1 + python3.7 无法正常使用 dj-db-conn-pool

报错如下:
Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/init.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/init.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/dj_db_conn_pool/core/mixins.py", line 65, in get_new_connection
**pool_params
File "/opt/workers/watt/.venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 97, in init
Pool.init(self, creator, **kw)
TypeError: init() got an unexpected keyword argument 'key'

Postgis backend broken (python 3.12.1, django==5.0.1, psycopg[binary,pool]==3.1.17, sqlalchemy==2.0.25)

Postgres backend works (except for postgis fields) but postgis backend does not. Tried to add 'server_version': '14.10' to DATABASES['default'] in django settings but does not help

portal-channels-1 | 2024-01-17 09:34:28,772 DEBUG core.py:98 dj_db_conn_pool.core.mixins.core.get_new_connection() default's pool has been created, parameter: {'pre_ping': True, 'echo': False, 'timeout': 30, 'recycle': 300, 'pool_size': 8, 'max_overflow': 32}
portal-channels-1 | 2024-01-17 09:34:28,784 DEBUG core.py:109 dj_db_conn_pool.core.mixins.core.get_new_connection() got default's connection <psycopg.Connection [IDLE] (host=postgresql database=portal) at 0x7f172b723650> from its pool
portal-channels-1 | Exception in thread django-main-thread:
portal-channels-1 | Traceback (most recent call last):
portal-channels-1 | File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
portal-channels-1 | self.run()
portal-channels-1 | File "/usr/local/lib/python3.12/threading.py", line 1010, in run
portal-channels-1 | self._target(*self._args, **self._kwargs)
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper
portal-channels-1 | fn(*args, **kwargs)
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/daphne/management/commands/runserver.py", line 97, in inner_run
portal-channels-1 | self.check_migrations()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/core/management/base.py", line 574, in check_migrations
portal-channels-1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/migrations/executor.py", line 18, in init
portal-channels-1 | self.loader = MigrationLoader(self.connection)
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/migrations/loader.py", line 58, in init
portal-channels-1 | self.build_graph()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/migrations/loader.py", line 235, in build_graph
portal-channels-1 | self.applied_migrations = recorder.applied_migrations()
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 89, in applied_migrations
portal-channels-1 | if self.has_table():
portal-channels-1 | ^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 63, in has_table
portal-channels-1 | with self.connection.cursor() as cursor:
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
portal-channels-1 | return func(*args, **kwargs)
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 316, in cursor
portal-channels-1 | return self._cursor()
portal-channels-1 | ^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 292, in _cursor
portal-channels-1 | self.ensure_connection()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
portal-channels-1 | return func(*args, **kwargs)
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 275, in ensure_connection
portal-channels-1 | self.connect()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
portal-channels-1 | return func(*args, **kwargs)
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 258, in connect
portal-channels-1 | self.init_connection_state()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/postgresql/base.py", line 309, in init_connection_state
portal-channels-1 | super().init_connection_state()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 225, in init_connection_state
portal-channels-1 | self.check_database_version_supported()
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/base.py", line 196, in check_database_version_supported
portal-channels-1 | and self.get_database_version() < self.features.minimum_database_version
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/postgresql/base.py", line 188, in get_database_version
portal-channels-1 | return divmod(self.pg_version, 10000)
portal-channels-1 | ^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/utils/functional.py", line 47, in get
portal-channels-1 | res = instance.dict[self.name] = self.func(instance)
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^
portal-channels-1 | File "/usr/local/lib/python3.12/site-packages/django/db/backends/postgresql/base.py", line 437, in pg_version
portal-channels-1 | return self.connection.info.server_version
portal-channels-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
portal-channels-1 | AttributeError: 'dict' object has no attribute 'server_version'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.