Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Driver Info into the MongoClient #210

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion django_mongodb/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import contextlib
import os

from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.base import BaseDatabaseWrapper
from pymongo.collection import Collection
from pymongo.driver_info import DriverInfo
from pymongo.mongo_client import MongoClient

from . import __version__ as django_mongodb_backend_version
from . import dbapi as Database
from .client import DatabaseClient
from .creation import DatabaseCreation
Expand Down Expand Up @@ -170,7 +173,12 @@ def get_connection_params(self):
}

def get_new_connection(self, conn_params):
return MongoClient(**conn_params)
return MongoClient(**conn_params, driver=self._driver_info())

def _driver_info(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a separate method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I like the separation is all.

if not os.environ.get("RUNNING_DJANGOS_TEST_SUITE"):
return DriverInfo("django-mongodb-backend", django_mongodb_backend_version)
return None

def _commit(self):
pass
Expand Down
Loading