File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 11from django .db .backends .base .features import BaseDatabaseFeatures
22from django .utils .functional import cached_property
3- from pymongo .errors import OperationFailure
3+ from pymongo .errors import CollectionInvalid , OperationFailure
44
55
66class DatabaseFeatures (BaseDatabaseFeatures ):
@@ -613,13 +613,21 @@ def django_test_expected_failures(self):
613613 def is_mongodb_6_3 (self ):
614614 return self .connection .get_database_version () >= (6 , 3 )
615615
616- @property
616+ @cached_property
617617 def supports_search_indexes (self ):
618+ dummy_collection = "__null"
618619 try :
619- # Try to execute an search indexes operation.
620- self .connection .get_collection ("__null" ).list_search_indexes ()
620+ # Try to execute an search indexes operation over an existing collection.
621+ try :
622+ collection = self .connection .database .create_collection (dummy_collection )
623+ except CollectionInvalid :
624+ # If the collection exists, it will be removed after this operation.
625+ collection = self .connection .get_collection (dummy_collection )
626+ collection .list_search_indexes ()
621627 except OperationFailure :
622- # Operation fails then search indexes isn't supported
628+ # Operation fails then search indexes isn't supported.
623629 return False
624630 else :
625631 return True
632+ finally :
633+ collection .drop ()
You can’t perform that action at this time.
0 commit comments