Skip to content

Commit ec88df4

Browse files
committed
Bug fix for options == None
1 parent ec854eb commit ec88df4

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

django_mongodb_backend/schema.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -430,29 +430,30 @@ def _create_collection(self, model):
430430
with `_get_encrypted_fields_map`.
431431
"""
432432
db = self.get_database()
433-
client = self.connection.connection
434-
options = client._options.auto_encryption_opts
435433
db_table = model._meta.db_table
436434
if getattr(model, "encrypted", False):
437-
schema_map = options._schema_map
438-
if schema_map:
439-
db.create_collection(db_table, encryptedFields=schema_map[db_table])
440-
else:
441-
key_vault_namespace = options._key_vault_namespace
442-
kms_providers = options._kms_providers
443-
ce = ClientEncryption(
444-
kms_providers, key_vault_namespace, client, client.codec_options
445-
)
446-
encrypted_fields_map = self._get_encrypted_fields_map(model)
447-
provider = router.kms_provider(model)
448-
credentials = self.connection.settings_dict.get("KMS_CREDENTIALS").get(provider)
449-
ce.create_encrypted_collection(
450-
db,
451-
db_table,
452-
encrypted_fields_map,
453-
provider,
454-
credentials,
455-
)
435+
client = self.connection.connection
436+
options = getattr(client._options, "auto_encryption_opts", None)
437+
if options is not None:
438+
schema_map = getattr(options, "_schema_map", None)
439+
if schema_map:
440+
db.create_collection(db_table, encryptedFields=schema_map[db_table])
441+
else:
442+
key_vault_namespace = options._key_vault_namespace
443+
kms_providers = options._kms_providers
444+
ce = ClientEncryption(
445+
kms_providers, key_vault_namespace, client, client.codec_options
446+
)
447+
encrypted_fields_map = self._get_encrypted_fields_map(model)
448+
provider = router.kms_provider(model)
449+
credentials = self.connection.settings_dict.get("KMS_CREDENTIALS").get(provider)
450+
ce.create_encrypted_collection(
451+
db,
452+
db_table,
453+
encrypted_fields_map,
454+
provider,
455+
credentials,
456+
)
456457
else:
457458
db.create_collection(db_table)
458459

0 commit comments

Comments
 (0)