File tree Expand file tree Collapse file tree 3 files changed +23
-20
lines changed
django_prometheus/db/backends Expand file tree Collapse file tree 3 files changed +23
-20
lines changed Original file line number Diff line number Diff line change
1
+ from django import VERSION
2
+
3
+
4
+ def get_postgres_cursor_class ():
5
+ if VERSION < (4 , 2 ):
6
+ from psycopg2 .extensions import cursor as cursor_cls
7
+ else :
8
+ from django .db .backends .postgresql .base import Cursor as cursor_cls
9
+ return cursor_cls
Original file line number Diff line number Diff line change 1
- from django import VERSION
2
1
from django .contrib .gis .db .backends .postgis import base
3
2
3
+ from django_prometheus .db .backends .common import get_postgres_cursor_class
4
4
from django_prometheus .db .common import DatabaseWrapperMixin , ExportingCursorWrapper
5
5
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
-
11
6
12
7
class DatabaseWrapper (DatabaseWrapperMixin , base .DatabaseWrapper ):
13
- def get_connection_params (self ):
14
- conn_params = super ().get_connection_params ()
15
- conn_params ["cursor_factory" ] = ExportingCursorWrapper (cursor_cls , "postgis" , self .vendor )
16
- return conn_params
8
+ def get_new_connection (self , * args , ** kwargs ):
9
+ conn = super ().get_new_connection (* args , ** kwargs )
10
+ conn .cursor_factory = ExportingCursorWrapper (
11
+ conn .cursor_factory or get_postgres_cursor_class (), "postgis" , self .vendor
12
+ )
13
+ return conn
17
14
18
15
def create_cursor (self , name = None ):
19
16
# cursor_factory is a kwarg to connect() so restore create_cursor()'s
Original file line number Diff line number Diff line change 1
- from django import VERSION
2
1
from django .contrib .gis .db .backends .postgis import base
3
2
3
+ from django_prometheus .db .backends .common import get_postgres_cursor_class
4
4
from django_prometheus .db .common import DatabaseWrapperMixin , ExportingCursorWrapper
5
5
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
-
11
6
12
7
class DatabaseWrapper (DatabaseWrapperMixin , base .DatabaseWrapper ):
13
- def get_connection_params (self ):
14
- conn_params = super ().get_connection_params ()
15
- conn_params ["cursor_factory" ] = ExportingCursorWrapper (cursor_cls , self .alias , self .vendor )
16
- return conn_params
8
+ def get_new_connection (self , * args , ** kwargs ):
9
+ conn = super ().get_new_connection (* args , ** kwargs )
10
+ conn .cursor_factory = ExportingCursorWrapper (
11
+ conn .cursor_factory or get_postgres_cursor_class (), self .alias , self .vendor
12
+ )
13
+ return conn
17
14
18
15
def create_cursor (self , name = None ):
19
16
# cursor_factory is a kwarg to connect() so restore create_cursor()'s
You can’t perform that action at this time.
0 commit comments