Skip to content

Commit 986782a

Browse files
jneightJavier Cordero
andauthored
support for django 5.1 (#94)
* added support for django 5.1 * add python 3.13 tests to github action drop support for django < 4.2 * new version 4.0.8 --------- Co-authored-by: Javier Cordero <github@j2i.me>
1 parent e573357 commit 986782a

File tree

14 files changed

+139
-33
lines changed

14 files changed

+139
-33
lines changed

.github/workflows/ci_psycopg2.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,40 @@ jobs:
1717
include:
1818
- os: ubuntu-latest
1919
python-version: '3.8'
20-
django-version: '3.2.23'
20+
django-version: '4.2.9'
2121
- os: ubuntu-latest
2222
python-version: '3.9'
23-
django-version: '3.2.23'
23+
django-version: '4.2.9'
2424
- os: ubuntu-latest
2525
python-version: '3.10'
26-
django-version: '3.2.23'
26+
django-version: '4.2.9'
2727
- os: ubuntu-latest
28-
python-version: '3.8'
28+
python-version: '3.11'
2929
django-version: '4.2.9'
3030
- os: ubuntu-latest
31-
python-version: '3.9'
31+
python-version: '3.12'
3232
django-version: '4.2.9'
3333
- os: ubuntu-latest
3434
python-version: '3.10'
35-
django-version: '4.2.9'
35+
django-version: '5.0.8'
3636
- os: ubuntu-latest
3737
python-version: '3.11'
38-
django-version: '4.2.9'
38+
django-version: '5.0.8'
3939
- os: ubuntu-latest
4040
python-version: '3.12'
41-
django-version: '4.2.9'
41+
django-version: '5.0.8'
42+
- os: ubuntu-latest
43+
python-version: '3.10'
44+
django-version: '5.1'
45+
- os: ubuntu-latest
46+
python-version: '3.11'
47+
django-version: '5.1'
48+
- os: ubuntu-latest
49+
python-version: '3.12'
50+
django-version: '5.1'
51+
- os: ubuntu-latest
52+
python-version: '3.13'
53+
django-version: '5.1'
4254
services:
4355
postgres:
4456
image: postgres

.github/workflows/ci_psycopg2_gis.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,40 @@ jobs:
1717
include:
1818
- os: ubuntu-latest
1919
python-version: '3.8'
20-
django-version: '3.2.23'
20+
django-version: '4.2.9'
2121
- os: ubuntu-latest
2222
python-version: '3.9'
23-
django-version: '3.2.23'
23+
django-version: '4.2.9'
2424
- os: ubuntu-latest
2525
python-version: '3.10'
26-
django-version: '3.2.23'
26+
django-version: '4.2.9'
2727
- os: ubuntu-latest
28-
python-version: '3.8'
28+
python-version: '3.11'
2929
django-version: '4.2.9'
3030
- os: ubuntu-latest
31-
python-version: '3.9'
31+
python-version: '3.12'
3232
django-version: '4.2.9'
3333
- os: ubuntu-latest
3434
python-version: '3.10'
35-
django-version: '4.2.9'
35+
django-version: '5.0.8'
3636
- os: ubuntu-latest
3737
python-version: '3.11'
38-
django-version: '4.2.9'
38+
django-version: '5.0.8'
3939
- os: ubuntu-latest
4040
python-version: '3.12'
41-
django-version: '4.2.9'
41+
django-version: '5.0.8'
42+
- os: ubuntu-latest
43+
python-version: '3.10'
44+
django-version: '5.1'
45+
- os: ubuntu-latest
46+
python-version: '3.11'
47+
django-version: '5.1'
48+
- os: ubuntu-latest
49+
python-version: '3.12'
50+
django-version: '5.1'
51+
- os: ubuntu-latest
52+
python-version: '3.13'
53+
django-version: '5.1'
4254
services:
4355
postgres:
4456
image: postgis/postgis

.github/workflows/ci_psycopg3.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ jobs:
3030
- os: ubuntu-latest
3131
python-version: '3.12'
3232
django-version: '4.2.9'
33+
- os: ubuntu-latest
34+
python-version: '3.10'
35+
django-version: '5.0.8'
36+
- os: ubuntu-latest
37+
python-version: '3.11'
38+
django-version: '5.0.8'
39+
- os: ubuntu-latest
40+
python-version: '3.12'
41+
django-version: '5.0.8'
42+
- os: ubuntu-latest
43+
python-version: '3.10'
44+
django-version: '5.1'
45+
- os: ubuntu-latest
46+
python-version: '3.11'
47+
django-version: '5.1'
48+
- os: ubuntu-latest
49+
python-version: '3.12'
50+
django-version: '5.1'
51+
- os: ubuntu-latest
52+
python-version: '3.13'
53+
django-version: '5.1'
3354
services:
3455
postgres:
3556
image: postgres

.github/workflows/ci_psycopg3_gis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ jobs:
3030
- os: ubuntu-latest
3131
python-version: '3.12'
3232
django-version: '4.2.9'
33+
- os: ubuntu-latest
34+
python-version: '3.10'
35+
django-version: '5.0.8'
36+
- os: ubuntu-latest
37+
python-version: '3.11'
38+
django-version: '5.0.8'
39+
- os: ubuntu-latest
40+
python-version: '3.12'
41+
django-version: '5.0.8'
42+
- os: ubuntu-latest
43+
python-version: '3.10'
44+
django-version: '5.1'
45+
- os: ubuntu-latest
46+
python-version: '3.11'
47+
django-version: '5.1'
48+
- os: ubuntu-latest
49+
python-version: '3.12'
50+
django-version: '5.1'
51+
- os: ubuntu-latest
52+
python-version: '3.13'
53+
django-version: '5.1'
3354
services:
3455
postgres:
3556
image: postgis/postgis

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Settings
6969
> persistent connection feature. And read below note if you are
7070
> manually spawning greenlets
7171
72+
For Django < 5.1:
73+
7274
``` {.python}
7375
DATABASES = {
7476
'default': {
@@ -88,6 +90,28 @@ DATABASES = {
8890
}
8991
```
9092

93+
For Django >= 5.1, native pool support should be disabled:
94+
95+
``` {.python}
96+
DATABASES = {
97+
'default': {
98+
'ENGINE': 'django_db_geventpool.backends.postgresql_psycopg',
99+
'NAME': 'db',
100+
'USER': 'postgres',
101+
'PASSWORD': 'postgres',
102+
'HOST': '',
103+
'PORT': '',
104+
'ATOMIC_REQUESTS': False,
105+
'CONN_MAX_AGE': 0,
106+
'OPTIONS': {
107+
'MAX_CONNS': 20,
108+
'REUSE_CONNS': 10.
109+
'pool': False,
110+
}
111+
}
112+
}
113+
```
114+
91115
Using ORM when not serving requests
92116
-----------------------------------
93117

django_db_geventpool/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = 'v4.0.7'
1+
version = 'v4.0.8'

django_db_geventpool/backends/base.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
logger = logging.getLogger("django.geventpool")
1212

13-
connection_pools = {}
1413
connection_pools_lock = Semaphore(value=1)
1514

1615

17-
class DatabaseWrapperMixin(object):
16+
class DatabaseWrapperMixin:
1817
pool_class = None
1918
creation_class = DatabaseCreation
2019
INTRANS = None
20+
_connection_pools = {}
21+
2122

2223
def __init__(self, *args, **kwargs):
2324
self._pool = None
@@ -29,11 +30,11 @@ def pool(self):
2930
if self._pool is not None:
3031
return self._pool
3132
with connection_pools_lock:
32-
if self.alias not in connection_pools:
33-
self._pool = self.pool_class(super(), **self.get_connection_params(), connect=lambda parent, **kw: parent.get_new_connection(conn_params=kw))
34-
connection_pools[self.alias] = self._pool
33+
if self.alias not in self._connection_pools:
34+
self._pool = self.pool_class(**self.get_connection_params())
35+
self._connection_pools[self.alias] = self._pool
3536
else:
36-
self._pool = connection_pools[self.alias]
37+
self._pool = self._connection_pools[self.alias]
3738
return self._pool
3839

3940
def get_new_connection(self, conn_params: dict):
@@ -62,7 +63,7 @@ def close(self):
6263
# will occur at every request.
6364
self.connection = None
6465
logger.warning(
65-
"psycopg2 error while closing the connection.", exc_info=sys.exc_info()
66+
"psycopg error while closing the connection.", exc_info=sys.exc_info()
6667
)
6768
raise
6869
finally:
@@ -74,7 +75,7 @@ def close_if_unusable_or_obsolete(self):
7475

7576
def _close(self):
7677
if self.connection.closed:
77-
self.pool.closeall()
78+
self.pool.close()
7879
else:
7980
if self.connection.info.transaction_status == self.INTRANS:
8081
self.connection.rollback()
@@ -84,8 +85,8 @@ def _close(self):
8485
self.connection = None
8586

8687
def closeall(self):
87-
for pool in connection_pools.values():
88-
pool.closeall()
88+
for pool in self._connection_pools.values():
89+
pool.close()
8990

9091
def set_clean(self):
9192
if self.in_atomic_block:

django_db_geventpool/backends/creation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
)
44

55

6-
class DatabaseCreationMixin(object):
6+
class DatabaseCreationMixin:
77
def _create_test_db(self, verbosity, autoclobber, keepdb=False):
8-
self.connection.closeall()
98
return super()._create_test_db(verbosity, autoclobber, keepdb)
109

1110
def _destroy_test_db(self, test_database_name, verbosity):

django_db_geventpool/backends/pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def put(self, item):
6868
item.close()
6969
self._conns.discard(item)
7070

71-
def closeall(self):
71+
def close(self):
7272
while not self.pool.empty():
7373
try:
7474
conn = self.pool.get_nowait()
@@ -82,3 +82,4 @@ def closeall(self):
8282
self._conns.discard(conn)
8383

8484
logger.debug("DB connections all closed")
85+

django_db_geventpool/backends/postgresql_psycopg3/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ def check_usable(self, connection):
3636
class DatabaseWrapper(base.DatabaseWrapperMixin, OriginalDatabaseWrapper):
3737
pool_class = PostgresConnectionPool
3838
INTRANS = psycopg.pq.TransactionStatus.INTRANS
39+
40+
41+

0 commit comments

Comments
 (0)