Skip to content

Commit 0e6e469

Browse files
committed
Renama schema_map -> encrypted_fields_map
- Client-side QE configuration mistakenly used `schema_map` to pass the encrypted fields map to Django's schema editor through `AutoEncryptionOpts`. Although confusing, and despite the error, client-side configuration still succeeded because the map given to `AutoEncryptionOpts` in `schema_map` was then correctly passed to `create_collection` via the `encryptedFields` arg. - Re-confirmed in local manual testing that client-side configuration works as expected and requires data keys. There is no code (as far as I can tell) to create data keys in PyMongo that is initiated by the existence of `encrypted_fields_map` alone. Rather, data keys appear to be created in `create_encrypted_collection` and only in `create_encrypted_collection`. - Renamed `showschemamap` -> `showfieldsmap` and updated tests and docs accordingly.
1 parent 53dbf08 commit 0e6e469

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

django_mongodb_backend/management/commands/showschemamap.py renamed to django_mongodb_backend/management/commands/showfieldsmap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class Command(BaseCommand):
11-
help = "Generate a `schema_map` of encrypted fields for all encrypted"
11+
help = "Generate an `encrypted_fields_map` of encrypted fields for all encrypted"
1212
" models in the database for use with `AutoEncryptionOpts` in"
1313
" client configuration."
1414

@@ -28,7 +28,7 @@ def add_arguments(self, parser):
2828
def handle(self, *args, **options):
2929
db = options["database"]
3030
connection = connections[db]
31-
schema_map = {}
31+
encrypted_fields_map = {}
3232
for app_config in apps.get_app_configs():
3333
for model in app_config.get_models():
3434
if has_encrypted_fields(model):
@@ -49,5 +49,5 @@ def handle(self, *args, **options):
4949
master_key=master_key,
5050
)
5151
field["keyId"] = data_key
52-
schema_map[model._meta.db_table] = fields
53-
self.stdout.write(json_util.dumps(schema_map, indent=2))
52+
encrypted_fields_map[model._meta.db_table] = fields
53+
self.stdout.write(json_util.dumps(encrypted_fields_map, indent=2))

django_mongodb_backend/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def _field_should_have_unique(self, field):
424424
def _create_collection(self, model):
425425
"""
426426
Create a collection for the model with the encrypted fields. If
427-
provided, use the `_schema_map` in the client's
427+
provided, use the `_encrypted_fields_map` in the client's
428428
`auto_encryption_opts`. Otherwise, create the encrypted fields map
429429
with `_get_encrypted_fields_map`.
430430
"""
@@ -434,8 +434,8 @@ def _create_collection(self, model):
434434
client = self.connection.connection
435435
options = getattr(client._options, "auto_encryption_opts", None)
436436
if options is not None:
437-
if schema_map := getattr(options, "_schema_map", None):
438-
db.create_collection(db_table, encryptedFields=schema_map[db_table])
437+
if encrypted_fields_map := getattr(options, "_encrypted_fields_map", None):
438+
db.create_collection(db_table, encryptedFields=encrypted_fields_map[db_table])
439439
else:
440440
ce = ClientEncryption(
441441
options._kms_providers,

docs/source/faq.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ In addition to the
7575
you will need to provide a ``schema_map`` to the ``AutoEncryptionOpts``.
7676

7777
Fortunately, this is easy to do with Django MongoDB Backend. You can use
78-
the ``showschemamap`` management command to generate the schema map
78+
the ``showfieldsmap`` management command to generate the schema map
7979
for your encrypted fields, and then use the results in your settings.
8080

8181
To generate the schema map, run the following command in your Django project:
8282
::
8383

84-
python manage.py showschemamap
84+
python manage.py showfieldsmap
8585

86-
.. note:: The ``showschemamap`` command is only available if you have the
86+
.. note:: The ``showfieldsmap`` command is only available if you have the
8787
``django_mongodb_backend`` app included in the :setting:`INSTALLED_APPS`
8888
setting.
8989

docs/source/ref/django-admin.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ Available commands
2828
Defaults to ``default``.
2929

3030

31-
``showschemamap``
31+
``showfieldsmap``
3232
----------------------------
3333

34-
.. django-admin:: showschemamap
34+
.. django-admin:: showfieldsmap
3535

36-
Creates a schema map for encrypted fields that can be used with
37-
:class:`~pymongo.encryption_options.AutoEncryptionOpts` to configure
38-
an encrypted client.
36+
Creates an encrypted fields map that can be used with `encrypted_fields_map`
37+
in :class:`~pymongo.encryption_options.AutoEncryptionOpts` to configure
38+
client-side Queryable Encryption.
3939

4040
.. django-admin-option:: --database DATABASE
4141

tests/encryption_/test_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_show_schema_map(self):
128128
self.maxDiff = None
129129
out = StringIO()
130130
call_command(
131-
"showschemamap",
131+
"showfieldsmap",
132132
"--database",
133133
"encrypted",
134134
verbosity=0,

0 commit comments

Comments
 (0)