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 DriverInfo to MongoClient creation #165

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion flask_pymongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
from pymongo import uri_parser
from werkzeug.wsgi import wrap_file
import pymongo
# DriverInfo was added in PyMongo 3.7
try:
from pymongo.driver_info import DriverInfo
except ImportError:
DriverInfo = None

from flask_pymongo._version import __version__
from flask_pymongo.helpers import BSONObjectIdConverter, JSONEncoder
from flask_pymongo.wrappers import MongoClient


DESCENDING = pymongo.DESCENDING
"""Descending sort order."""

Expand Down Expand Up @@ -109,6 +114,8 @@ def init_app(self, app, uri=None, *args, **kwargs):
# Try to delay connecting, in case the app is loaded before forking, per
# http://api.mongodb.com/python/current/faq.html#is-pymongo-fork-safe
kwargs.setdefault("connect", False)
if DriverInfo is not None:
kwargs.setdefault("driver", DriverInfo("Flask-PyMongo", __version__))

self.cx = MongoClient(*args, **kwargs)
if database_name:
Expand Down