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 1 commit
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
7 changes: 6 additions & 1 deletion django_mongodb/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import contextlib
from importlib import metadata

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 dbapi as Database
Expand Down Expand Up @@ -170,7 +172,10 @@ 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
Contributor 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.

return DriverInfo("django-mongodb", metadata.version("django-mongodb"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than using importlib.metadata you could use from . import __version__ as django_mongodb_version (this is what I used in other libraries).


def _commit(self):
pass
Expand Down
Loading