Skip to content

Commit 65bd15a

Browse files
committed
Fix test for unencrypted field not in field map
1 parent 38fb110 commit 65bd15a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

django_mongodb_backend/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS):
160160
# Cache the `settings_dict` in case we need to check for
161161
# auto_encryption_opts later.
162162
self.__dict__["_settings_dict"] = copy.deepcopy(settings_dict)
163+
self.encrypted_connection = None
163164

164165
def get_collection(self, name, **kwargs):
165166
collection = Collection(self.database, name, **kwargs)

django_mongodb_backend/schema.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,17 @@ def _create_collection(self, model):
447447
auto_encryption_opts = self.connection._settings_dict.get("OPTIONS", {}).get(
448448
"auto_encryption_opts"
449449
)
450-
# Use the cached settings dict to create a new connection
451-
encrypted_connection = self.connection.get_new_connection(
452-
self.connection._settings_dict
453-
)
450+
if not self.connection.encrypted_connection:
451+
# Use the cached settings dict to create a new connection
452+
self.encrypted_connection = self.connection.get_new_connection(
453+
self.connection._settings_dict
454+
)
454455
# Use the encrypted connection and auto_encryption_opts to create an encrypted client
455-
encrypted_client = get_encrypted_client(auto_encryption_opts, encrypted_connection)
456+
encrypted_client = get_encrypted_client(auto_encryption_opts, self.encrypted_connection)
456457

457458
with contextlib.suppress(EncryptedCollectionError):
458459
encrypted_client.create_encrypted_collection(
459-
encrypted_connection[self.connection.database.name],
460+
self.encrypted_connection[self.connection.database.name],
460461
model._meta.db_table,
461462
model.encrypted_fields_map,
462463
"local", # TODO: KMS provider should be configurable

0 commit comments

Comments
 (0)