44from django .db import router
55from django .db .backends .base .schema import BaseDatabaseSchemaEditor
66from django .db .models import Index , UniqueConstraint
7- from pymongo .encryption import ClientEncryption
87from pymongo .operations import SearchIndexModel
98
109from django_mongodb_backend .indexes import SearchIndex
@@ -483,9 +482,7 @@ def _create_collection(self, model):
483482 else :
484483 db .create_collection (db_table )
485484
486- def _get_encrypted_fields (
487- self , model , create_data_keys = False , key_alt_name = None , client_encryption = None
488- ):
485+ def _get_encrypted_fields (self , model , create_data_keys = False , key_alt_name = None ):
489486 """
490487 Recursively collect encryption schema data for fields in a model.
491488
@@ -502,15 +499,7 @@ def _get_encrypted_fields(
502499 key_vault_collection = client [key_vault_db ][key_vault_coll ]
503500 kms_provider = router .kms_provider (model )
504501 master_key = connection .settings_dict .get ("KMS_CREDENTIALS" , {}).get (kms_provider )
505-
506- # Initialize ClientEncryption once
507- if client_encryption is None :
508- client_encryption = ClientEncryption (
509- auto_encryption_opts ._kms_providers ,
510- auto_encryption_opts ._key_vault_namespace ,
511- client ,
512- client .codec_options ,
513- )
502+ client_encryption = self .connection .client_encryption
514503
515504 field_list = []
516505
@@ -551,7 +540,6 @@ def _get_encrypted_fields(
551540 field .embedded_model ,
552541 create_data_keys = create_data_keys ,
553542 key_alt_name = new_path ,
554- client_encryption = client_encryption ,
555543 )
556544 field_list .extend (embedded_result ["fields" ])
557545 continue
0 commit comments