@@ -479,7 +479,9 @@ def _create_collection(self, model):
479
479
else :
480
480
encrypted_fields = encrypted_fields_map .get (db_table )
481
481
482
- if encrypted_fields and encrypted_fields .get ("fields" ):
482
+ # if encrypted_fields and encrypted_fields.get("fields"):
483
+
484
+ if encrypted_fields :
483
485
db .create_collection (db_table , encryptedFields = encrypted_fields )
484
486
else :
485
487
db .create_collection (db_table )
@@ -489,20 +491,20 @@ def _create_collection(self, model):
489
491
db .create_collection (db_table )
490
492
491
493
def _get_encrypted_fields (
492
- self , model , create_data_keys = False , key_alt_name = None , parent_model = None
494
+ self , model , create_data_keys = False , key_alt_name = None , path_prefix = None
493
495
):
494
496
"""
495
497
Recursively collect encryption schema data for only encrypted fields in a model.
496
498
Returns None if no encrypted fields are found anywhere in the model hierarchy.
497
499
498
500
key_alt_name is the base path used for keyAltNames.
499
- parent_model is the dot-notated path inside the document for schema mapping.
501
+ path_prefix is the dot-notated path inside the document for schema mapping.
500
502
"""
501
503
connection = self .connection
502
504
client = connection .connection
503
505
fields = model ._meta .fields
504
506
key_alt_name = key_alt_name or model ._meta .db_table
505
- parent_model = parent_model or ""
507
+ path_prefix = path_prefix or ""
506
508
507
509
options = client ._options
508
510
auto_encryption_opts = getattr (options , "auto_encryption_opts" , None )
@@ -520,7 +522,7 @@ def _get_encrypted_fields(
520
522
521
523
for field in fields :
522
524
new_key_alt_name = f"{ key_alt_name } .{ field .column } "
523
- new_parent_model = f"{ parent_model } .{ field .column } " if parent_model else field .column
525
+ path = f"{ path_prefix } .{ field .column } " if path_prefix else field .column
524
526
525
527
# --- EmbeddedModelField ---
526
528
if isinstance (field , EmbeddedModelField ):
@@ -550,7 +552,7 @@ def _get_encrypted_fields(
550
552
551
553
field_dict = {
552
554
"bsonType" : "object" ,
553
- "path" : new_parent_model ,
555
+ "path" : path ,
554
556
"keyId" : data_key ,
555
557
}
556
558
if getattr (field , "queries" , False ):
@@ -563,7 +565,7 @@ def _get_encrypted_fields(
563
565
field .embedded_model ,
564
566
create_data_keys = create_data_keys ,
565
567
key_alt_name = new_key_alt_name ,
566
- parent_model = new_parent_model ,
568
+ path_prefix = path ,
567
569
)
568
570
if embedded_result and embedded_result .get ("fields" ):
569
571
field_list .extend (embedded_result ["fields" ])
@@ -595,7 +597,7 @@ def _get_encrypted_fields(
595
597
596
598
field_dict = {
597
599
"bsonType" : field .db_type (connection ),
598
- "path" : new_parent_model ,
600
+ "path" : path ,
599
601
"keyId" : data_key ,
600
602
}
601
603
if getattr (field , "queries" , False ):
0 commit comments