Skip to content

Commit 6225027

Browse files
authored
add django 4.2 support (#351)
* add django 4.2 support
1 parent 4872a34 commit 6225027

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Support new cache backend names in newer Django versions, Thanks [@tneuct](https://github.com/korfuri/django-prometheus/pull/329)
88
* Make export of migrations False by default, Thanks [@kaypee90](https://github.com/korfuri/django-prometheus/pull/313)
99
* Add support for Django 4.1, Python 3.11
10+
* Add support for Django 4.2 and Psycopg 3
1011

1112
## v2.2.0 - December 19, 2021
1213

django_prometheus/db/backends/postgis/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import psycopg2.extensions
1+
from django import VERSION
22
from django.contrib.gis.db.backends.postgis import base
33

44
from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWrapper
55

6+
if VERSION < (4, 2):
7+
from psycopg2.extensions import cursor as cursor_cls
8+
else:
9+
from django.db.backends.postgresql.base import Cursor as cursor_cls
10+
611

712
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
813
def get_connection_params(self):
914
conn_params = super().get_connection_params()
10-
conn_params["cursor_factory"] = ExportingCursorWrapper(psycopg2.extensions.cursor, "postgis", self.vendor)
15+
conn_params["cursor_factory"] = ExportingCursorWrapper(cursor_cls, "postgis", self.vendor)
1116
return conn_params
1217

1318
def create_cursor(self, name=None):

django_prometheus/db/backends/postgresql/base.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import psycopg2.extensions
2-
from django.db.backends.postgresql import base
1+
from django import VERSION
2+
from django.contrib.gis.db.backends.postgis import base
33

44
from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWrapper
55

6-
7-
class DatabaseFeatures(base.DatabaseFeatures):
8-
"""Our database has the exact same features as the base one."""
9-
10-
pass
6+
if VERSION < (4, 2):
7+
from psycopg2.extensions import cursor as cursor_cls
8+
else:
9+
from django.db.backends.postgresql.base import Cursor as cursor_cls
1110

1211

1312
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
1413
def get_connection_params(self):
1514
conn_params = super().get_connection_params()
16-
conn_params["cursor_factory"] = ExportingCursorWrapper(psycopg2.extensions.cursor, self.alias, self.vendor)
15+
conn_params["cursor_factory"] = ExportingCursorWrapper(cursor_cls, self.alias, self.vendor)
1716
return conn_params
1817

1918
def create_cursor(self, name=None):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def get_version():
5959
"Framework :: Django :: 3.2",
6060
"Framework :: Django :: 4.0",
6161
"Framework :: Django :: 4.1",
62+
"Framework :: Django :: 4.2",
6263
"Topic :: System :: Monitoring",
6364
"License :: OSI Approved :: Apache Software License",
6465
],

0 commit comments

Comments
 (0)