1
- import contextlib
2
-
3
1
from django .db .backends .base .schema import BaseDatabaseSchemaEditor
4
2
from django .db .models import Index , UniqueConstraint
5
- from pymongo .encryption import EncryptedCollectionError
6
3
from pymongo .operations import SearchIndexModel
7
4
8
5
from .encryption import get_encrypted_client
@@ -425,8 +422,8 @@ def _field_should_have_unique(self, field):
425
422
def _create_collection (self , model ):
426
423
"""
427
424
Create a collection or, if encryption is supported, create
428
- an encrypted connection then use it to create an encrypted
429
- client then use that to create an encrypted collection.
425
+ an encrypted client then use that to create an encrypted
426
+ collection.
430
427
"""
431
428
432
429
if hasattr (model , "encrypted_fields_map" ):
@@ -435,15 +432,11 @@ def _create_collection(self, model):
435
432
)
436
433
client = self .connection .connection
437
434
encrypted_client = get_encrypted_client (auto_encryption_opts , client )
438
-
439
- # If the collection exists, `create_encrypted_collection` will raise an
440
- # EncryptedCollectionError.
441
- with contextlib .suppress (EncryptedCollectionError ):
442
- encrypted_client .create_encrypted_collection (
443
- client .database ,
444
- model ._meta .db_table ,
445
- model .encrypted_fields_map ,
446
- "local" , # TODO: KMS provider should be configurable
447
- )
435
+ encrypted_client .create_encrypted_collection (
436
+ client .database ,
437
+ model ._meta .db_table ,
438
+ model .encrypted_fields_map ,
439
+ "local" , # TODO: KMS provider should be configurable
440
+ )
448
441
else :
449
442
self .get_database ().create_collection (model ._meta .db_table )
0 commit comments