1010from django .db import DEFAULT_DB_ALIAS
1111from django .db .backends import util
1212from django .db .transaction import TransactionManagementError
13+ from django .utils .functional import cached_property
1314from django .utils .importlib import import_module
1415from django .utils .timezone import is_aware
1516
@@ -402,28 +403,19 @@ class BaseDatabaseFeatures(object):
402403 # Does the backend reset sequences between tests?
403404 supports_sequence_reset = True
404405
405- # Features that need to be confirmed at runtime
406- # Cache whether the confirmation has been performed.
407- _confirmed = False
408- supports_transactions = None
409- supports_stddev = None
410- can_introspect_foreign_keys = None
406+ # Confirm support for introspected foreign keys
407+ # Every database can do this reliably, except MySQL,
408+ # which can't do it for MyISAM tables
409+ can_introspect_foreign_keys = True
411410
412411 # Support for the DISTINCT ON clause
413412 can_distinct_on_fields = False
414413
415414 def __init__ (self , connection ):
416415 self .connection = connection
417416
418- def confirm (self ):
419- "Perform manual checks of any database features that might vary between installs"
420- if not self ._confirmed :
421- self ._confirmed = True
422- self .supports_transactions = self ._supports_transactions ()
423- self .supports_stddev = self ._supports_stddev ()
424- self .can_introspect_foreign_keys = self ._can_introspect_foreign_keys ()
425-
426- def _supports_transactions (self ):
417+ @cached_property
418+ def supports_transactions (self ):
427419 "Confirm support for transactions"
428420 cursor = self .connection .cursor ()
429421 cursor .execute ('CREATE TABLE ROLLBACK_TEST (X INT)' )
@@ -436,7 +428,8 @@ def _supports_transactions(self):
436428 self .connection ._commit ()
437429 return count == 0
438430
439- def _supports_stddev (self ):
431+ @cached_property
432+ def supports_stddev (self ):
440433 "Confirm support for STDDEV and related stats functions"
441434 class StdDevPop (object ):
442435 sql_function = 'STDDEV_POP'
@@ -447,12 +440,6 @@ class StdDevPop(object):
447440 except NotImplementedError :
448441 return False
449442
450- def _can_introspect_foreign_keys (self ):
451- "Confirm support for introspected foreign keys"
452- # Every database can do this reliably, except MySQL,
453- # which can't do it for MyISAM tables
454- return True
455-
456443
457444class BaseDatabaseOperations (object ):
458445 """
0 commit comments