Skip to content

Commit b13a07f

Browse files
committed
Fix get_database_version
I was unable to do this in `init_connection_state` so I tried to do the next best thing.
1 parent c751b2d commit b13a07f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

django_mongodb_backend/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import os
33

44
from django.core.exceptions import ImproperlyConfigured
5-
from django.db import DEFAULT_DB_ALIAS
5+
from django.db import DEFAULT_DB_ALIAS, connections
66
from django.db.backends.base.base import BaseDatabaseWrapper
77
from django.db.backends.utils import debug_transaction
88
from django.utils.asyncio import async_unsafe
99
from django.utils.functional import cached_property
1010
from pymongo.collection import Collection
1111
from pymongo.driver_info import DriverInfo
12+
from pymongo.errors import EncryptionError
1213
from pymongo.mongo_client import MongoClient
1314

1415
from . import __version__ as django_mongodb_backend_version
@@ -286,5 +287,10 @@ def validate_no_broken_transaction(self):
286287

287288
def get_database_version(self):
288289
"""Return a tuple of the database's version."""
289-
# return tuple(self.connection.server_info()["versionArray"])
290-
return (8, 1, 1)
290+
try:
291+
return tuple(self.connection.server_info()["versionArray"])
292+
except EncryptionError:
293+
# Work around self.connection.server_info's refusal to work
294+
# with encrypted connections.
295+
default_connection = connections[DEFAULT_DB_ALIAS]
296+
return default_connection.get_database_version()

0 commit comments

Comments
 (0)