From 04a0b772fcfac9af6515b3338d7140db3b737ecf Mon Sep 17 00:00:00 2001 From: Dillon Walls Date: Mon, 7 Oct 2024 12:13:42 -0400 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! add support for mongodb Client Side Field Level Encryption (CSFLE) --- ming/encryption.py | 9 ++++++++- ming/tests/test_encryption.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ming/encryption.py b/ming/encryption.py index ee1e0f9..f933872 100644 --- a/ming/encryption.py +++ b/ming/encryption.py @@ -8,6 +8,7 @@ if TYPE_CHECKING: import ming.datastore from ming.metadata import Field + from ming.odm.property import FieldProperty class MingEncryptionError(Exception): @@ -150,7 +151,13 @@ def _field_names(cls) -> list[str]: field_names.append(k) return field_names if issubclass(cls, MappedClass): - return list(cls.query.mapper.property_index.keys()) + fields: list[tuple[str, FieldProperty]] = list(cls.query.mapper.property_index.items()) + field_names = [] + for (k, v) in fields: + if v.field.type in (ming.schema.Deprecated,): + continue + field_names.append(k) + return field_names raise NotImplementedError("Unexpected class type. You must implement `field_names` as a @classproperty in your mixin implementation.") @classmethod diff --git a/ming/tests/test_encryption.py b/ming/tests/test_encryption.py index aa62a61..097226e 100644 --- a/ming/tests/test_encryption.py +++ b/ming/tests/test_encryption.py @@ -243,6 +243,7 @@ class __mongometa__: name = DecryptedField(str, 'name_encrypted') name_encrypted = Field(S.Binary) other = Field(str) + deprecated = FieldProperty(S.Deprecated) doc = TestDoc.make_encr(dict(_id=1, name='Jerome', other='foo')) doc.m.save() @@ -303,6 +304,7 @@ class __mongometa__: name = DecryptedProperty(str, 'name_encrypted') name_encrypted = FieldProperty(S.Binary) other = FieldProperty(str) + deprecated = FieldProperty(S.Deprecated) u = TestMapped(_id=None, name="Jerome", other='foo') self.session.flush()