1
- import time
2
-
3
1
from django .db .backends .base .base import timezone_constructor
4
2
from django .db .backends .postgresql .operations import (
5
3
DatabaseOperations as PostgresDatabaseOperations ,
6
4
)
7
- from django .db .utils import OperationalError
8
- from psycopg2 import errorcodes
9
5
10
6
11
7
class DatabaseOperations (PostgresDatabaseOperations ):
@@ -22,23 +18,6 @@ class DatabaseOperations(PostgresDatabaseOperations):
22
18
}
23
19
explain_options = frozenset (['DISTSQL' , 'OPT' , 'TYPES' , 'VEC' , 'VERBOSE' ])
24
20
25
- def datetime_extract_sql (self , lookup_type , sql , params , tzname ):
26
- if self .connection .features .is_cockroachdb_22_1 :
27
- return super ().datetime_extract_sql (lookup_type , sql , params , tzname )
28
- # Override the changes from https://github.com/django/django/commit/b7f263551c64e3f80544892e314ed5b0b22cc7c8
29
- # which aren't compatible with older versions of CockroachDB:
30
- # https://github.com/cockroachdb/cockroach/issues/76960
31
- sql , params = self ._convert_sql_to_tz (sql , params , tzname )
32
- return self .date_extract_sql (lookup_type , sql , params )
33
-
34
- def time_extract_sql (self , lookup_type , sql , params ):
35
- if self .connection .features .is_cockroachdb_22_1 :
36
- return super ().time_extract_sql (lookup_type , sql , params )
37
- # Override the changes from https://github.com/django/django/commit/b7f263551c64e3f80544892e314ed5b0b22cc7c8
38
- # which aren't compatible with older versions of CockroachDB:
39
- # https://github.com/cockroachdb/cockroach/issues/76960
40
- return self .date_extract_sql (lookup_type , sql , params )
41
-
42
21
def deferrable_sql (self ):
43
22
# Deferrable constraints aren't supported:
44
23
# https://github.com/cockroachdb/cockroach/issues/31632
@@ -79,22 +58,6 @@ def explain_query_prefix(self, format=None, **options):
79
58
prefix += ' (%s)' % ', ' .join (extra )
80
59
return prefix
81
60
82
- def execute_sql_flush (self , sql_list ):
83
- # Retry TRUNCATE if it fails with a serialization error.
84
- num_retries = 10
85
- initial_retry_delay = 0.5 # The initial retry delay, in seconds.
86
- backoff_ = 1.5 # For each retry, the last delay is multiplied by this.
87
- next_retry_delay = initial_retry_delay
88
- for retry in range (1 , num_retries + 1 ):
89
- try :
90
- return super ().execute_sql_flush (sql_list )
91
- except OperationalError as exc :
92
- if (getattr (exc .__cause__ , 'pgcode' , '' ) != errorcodes .SERIALIZATION_FAILURE or
93
- retry >= num_retries ):
94
- raise
95
- time .sleep (next_retry_delay )
96
- next_retry_delay *= backoff_
97
-
98
61
def sql_flush (self , style , tables , * , reset_sequences = False , allow_cascade = False ):
99
62
# CockroachDB doesn't support resetting sequences.
100
63
return super ().sql_flush (style , tables , reset_sequences = False , allow_cascade = allow_cascade )
0 commit comments