Skip to content

Commit 8e83ada

Browse files
committed
Remove _nodb_cursor and disable version check
1 parent 7b34b44 commit 8e83ada

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
lines changed

django_mongodb_backend/base.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import contextlib
2-
import copy
32
import os
43

54
from django.core.exceptions import ImproperlyConfigured
65
from django.db import DEFAULT_DB_ALIAS
7-
from django.db.backends.base.base import NO_DB_ALIAS, BaseDatabaseWrapper
6+
from django.db.backends.base.base import BaseDatabaseWrapper
87
from django.db.backends.utils import debug_transaction
98
from django.utils.asyncio import async_unsafe
109
from django.utils.functional import cached_property
@@ -157,10 +156,6 @@ def _isnull_operator(a, b):
157156
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS):
158157
super().__init__(settings_dict, alias=alias)
159158
self.session = None
160-
# Cache the `settings_dict` in case we need to check for
161-
# auto_encryption_opts later.
162-
self.__dict__["_settings_dict"] = copy.deepcopy(settings_dict)
163-
self.encrypted_connection = None
164159

165160
def get_collection(self, name, **kwargs):
166161
collection = Collection(self.database, name, **kwargs)
@@ -291,26 +286,6 @@ def validate_no_broken_transaction(self):
291286

292287
def get_database_version(self):
293288
"""Return a tuple of the database's version."""
294-
return tuple(self.connection.server_info()["versionArray"])
295-
296-
@contextlib.contextmanager
297-
def _nodb_cursor(self):
298-
"""
299-
Returns a cursor from an unencrypted connection for operations
300-
that do not support encryption.
301-
302-
Encryption is only supported on encrypted models.
303-
"""
304-
305-
# Remove auto_encryption_opts from OPTIONS
306-
if self.settings_dict.get("OPTIONS", {}).get("auto_encryption_opts"):
307-
self.settings_dict["OPTIONS"].pop("auto_encryption_opts")
308-
309-
# Create a new connection without OPTIONS["auto_encryption_opts": …]
310-
conn = self.__class__({**self.settings_dict}, alias=NO_DB_ALIAS)
311-
312-
try:
313-
with conn.cursor() as cursor:
314-
yield cursor
315-
finally:
316-
conn.close()
289+
return (8, 1, 1)
290+
# TODO: provide an unencrypted connection for this method.
291+
# return tuple(self.connection.server_info()["versionArray"])

django_mongodb_backend/schema.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,22 +430,17 @@ def _create_collection(self, model):
430430
"""
431431

432432
if hasattr(model, "encrypted_fields_map"):
433-
auto_encryption_opts = self.connection._settings_dict.get("OPTIONS", {}).get(
433+
auto_encryption_opts = self.connection.settings_dict.get("OPTIONS", {}).get(
434434
"auto_encryption_opts"
435435
)
436-
if not self.connection.encrypted_connection:
437-
# Use the cached settings dict to create a new connection
438-
self.encrypted_connection = self.connection.get_new_connection(
439-
self.connection._settings_dict
440-
)
441-
# Use the encrypted connection and auto_encryption_opts to create an encrypted client
442-
encrypted_client = get_encrypted_client(auto_encryption_opts, self.encrypted_connection)
436+
client = self.connection.connection
437+
encrypted_client = get_encrypted_client(auto_encryption_opts, client)
443438

444439
# If the collection exists, `create_encrypted_collection` will raise an
445440
# EncryptedCollectionError.
446441
with contextlib.suppress(EncryptedCollectionError):
447442
encrypted_client.create_encrypted_collection(
448-
self.encrypted_connection[self.connection.database.name],
443+
client.database,
449444
model._meta.db_table,
450445
model.encrypted_fields_map,
451446
"local", # TODO: KMS provider should be configurable

0 commit comments

Comments
 (0)