Skip to content

Commit e519cd1

Browse files
committed
Copilot review fixes
1 parent fa61a7c commit e519cd1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

django_mongodb_backend/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def get_database_version(self):
251251
"""Return a tuple of the database's version."""
252252
# This can use PyMongo's
253253
# `tuple(self.connection.server_info()["versionArray"])` on
254-
# pymongocrypt>=1.14.2. See: https://jira.mongodb.org/browse/PYTHON-5429
254+
# TODO: Replace with `tuple(self.connection.server_info()["versionArray"])` once
255+
# pymongocrypt >= 1.14.2 is required and PYTHON-5429 is resolved.
256+
# See: https://jira.mongodb.org/browse/PYTHON-5429
255257
return tuple(self.connection.admin.command("buildInfo")["versionArray"])
256258

257259
## Transaction API for django_mongodb_backend.transaction.atomic()

django_mongodb_backend/routers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def allow_migrate(self, db, app_label, model_name=None, **hints):
2222

2323
# This function is intended to be monkey-patched as a method of ConnectionRouter.
2424
def kms_provider(self, model, *args, **kwargs):
25+
"""
26+
Monkey-patched method for ConnectionRouter to resolve a KMS provider for a given model.
27+
Iterates through all configured database routers, calling their `kms_provider` method (if present)
28+
to determine the appropriate Key Management Service (KMS) provider for the specified model.
29+
Returns the first non-None result found. Raises ImproperlyConfigured if no provider is found.
30+
"""
2531
for router in self.routers:
2632
func = getattr(router, "kms_provider", None)
2733
if func and callable(func):

django_mongodb_backend/schema.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _create_collection(self, model):
440440
raise ImproperlyConfigured(
441441
"Encrypted fields found but "
442442
f"DATABASES[{self.connection.alias}]['OPTIONS'] is missing "
443-
"auto_encryption_opts."
443+
f"Encrypted fields found but DATABASES['{self.connection.alias}']['OPTIONS'] is missing auto_encryption_opts."
444444
)
445445
encrypted_fields_map = getattr(auto_encryption_opts, "_encrypted_fields_map", None)
446446
if not encrypted_fields_map:
@@ -484,7 +484,10 @@ def _get_encrypted_fields_map(self, model, client, create_data_keys=False):
484484
else:
485485
key_doc = key_vault_collection.find_one({"keyAltNames": key_alt_name})
486486
if not key_doc:
487-
raise ValueError(f"No key found in keyvault for keyAltName={key_alt_name}")
487+
raise ValueError(
488+
f"No key found in keyvault for keyAltName={key_alt_name}. "
489+
"You may need to run the management command with '--create-data-keys' to create missing keys."
490+
)
488491
data_key = key_doc["_id"]
489492
field_dict = {
490493
"bsonType": field.db_type(connection),

0 commit comments

Comments
 (0)