diff --git a/flask_pymongo/__init__.py b/flask_pymongo/__init__.py index 5e0fc14..974202d 100644 --- a/flask_pymongo/__init__.py +++ b/flask_pymongo/__init__.py @@ -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.""" @@ -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: