File tree 1 file changed +13
-5
lines changed
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 ):
@@ -613,13 +613,21 @@ def django_test_expected_failures(self):
613
613
def is_mongodb_6_3 (self ):
614
614
return self .connection .get_database_version () >= (6 , 3 )
615
615
616
- @property
616
+ @cached_property
617
617
def supports_search_indexes (self ):
618
+ dummy_collection = "__null"
618
619
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 ()
621
627
except OperationFailure :
622
- # Operation fails then search indexes isn't supported
628
+ # Operation fails then search indexes isn't supported.
623
629
return False
624
630
else :
625
631
return True
632
+ finally :
633
+ collection .drop ()
You can’t perform that action at this time.
0 commit comments