Skip to content

Commit 7b34b44

Browse files
committed
Don't rely on features to fall back to unencrypted
1 parent e08945b commit 7b34b44

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

django_mongodb_backend/schema.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,28 +422,14 @@ def _field_should_have_unique(self, field):
422422
# The _id column is automatically unique.
423423
return db_type and field.unique and field.column != "_id"
424424

425-
def _supports_encryption(self, model):
426-
"""
427-
Check for `supports_encryption` feature and `auto_encryption_opts`
428-
and `embedded_fields_map`. If `supports_encryption` is True and
429-
`auto_encryption_opts` is in the cached connection settings and
430-
the model has an embedded_fields_map property, then encryption
431-
is supported.
432-
"""
433-
return (
434-
self.connection.features.supports_encryption
435-
and self.connection._settings_dict.get("OPTIONS", {}).get("auto_encryption_opts")
436-
and hasattr(model, "encrypted_fields_map")
437-
)
438-
439425
def _create_collection(self, model):
440426
"""
441427
Create a collection or, if encryption is supported, create
442428
an encrypted connection then use it to create an encrypted
443429
client then use that to create an encrypted collection.
444430
"""
445431

446-
if self._supports_encryption(model):
432+
if hasattr(model, "encrypted_fields_map"):
447433
auto_encryption_opts = self.connection._settings_dict.get("OPTIONS", {}).get(
448434
"auto_encryption_opts"
449435
)

tests/encryption_/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
class Person(EncryptedModel):
8-
ssn = EncryptedCharField("ssn", max_length=11)
98
name = models.CharField("name", max_length=100)
9+
ssn = EncryptedCharField("ssn", max_length=11)
1010

1111
def __str__(self):
12-
return self.ssn
12+
return self.name

0 commit comments

Comments
 (0)