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 ):
@@ -627,13 +627,21 @@ def django_test_expected_failures(self):
627
627
def is_mongodb_6_3 (self ):
628
628
return self .connection .get_database_version () >= (6 , 3 )
629
629
630
- @property
630
+ @cached_property
631
631
def supports_search_indexes (self ):
632
+ dummy_collection = "__null"
632
633
try :
633
- # Try to execute an search indexes operation.
634
- self .connection .get_collection ("__null" ).list_search_indexes ()
634
+ # Try to execute an search indexes operation over an existing collection.
635
+ try :
636
+ collection = self .connection .database .create_collection (dummy_collection )
637
+ except CollectionInvalid :
638
+ # If the collection exists, it will be removed after this operation.
639
+ collection = self .connection .get_collection (dummy_collection )
640
+ collection .list_search_indexes ()
635
641
except OperationFailure :
636
- # Operation fails then search indexes isn't supported
642
+ # Operation fails then search indexes isn't supported.
637
643
return False
638
644
else :
639
645
return True
646
+ finally :
647
+ collection .drop ()
You can’t perform that action at this time.
0 commit comments