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 1
1
from django .db .backends .base .features import BaseDatabaseFeatures
2
2
from django .utils .functional import cached_property
3
- from pymongo .errors import OperationFailure
3
+ from pymongo .errors import CollectionInvalid , OperationFailure
4
4
5
5
6
6
class DatabaseFeatures (BaseDatabaseFeatures ):
@@ -550,13 +550,21 @@ def django_test_expected_failures(self):
550
550
def is_mongodb_6_3 (self ):
551
551
return self .connection .get_database_version () >= (6 , 3 )
552
552
553
- @property
553
+ @cached_property
554
554
def supports_search_indexes (self ):
555
+ dummy_collection = "__null"
555
556
try :
556
- # Try to execute an search indexes operation.
557
- self .connection .get_collection ("__null" ).list_search_indexes ()
557
+ # Try to execute an search indexes operation over an existing collection.
558
+ try :
559
+ collection = self .connection .database .create_collection (dummy_collection )
560
+ except CollectionInvalid :
561
+ # If the collection exists, it will be removed after this operation.
562
+ collection = self .connection .get_collection (dummy_collection )
563
+ collection .list_search_indexes ()
558
564
except OperationFailure :
559
- # Operation fails then search indexes isn't supported
565
+ # Operation fails then search indexes isn't supported.
560
566
return False
561
567
else :
562
568
return True
569
+ finally :
570
+ collection .drop ()
You can’t perform that action at this time.
0 commit comments