Skip to content

Commit

Permalink
fix: don't log if pymongo is unavailable, instead crash if requested …
Browse files Browse the repository at this point in the history
…and unavailable
  • Loading branch information
ErikBjare committed Apr 27, 2022
1 parent 9ffe47c commit 2e999f0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions aw_datastore/storages/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

import iso8601

# MongoDB
# will be unavailable if pymongo is
try:
import pymongo
from bson.objectid import ObjectId
except ImportError: # pragma: no cover
logging.warning("Could not import pymongo, not available as a datastore backend")
except ImportError:
pass

from aw_core.models import Event

Expand All @@ -25,6 +24,14 @@ class MongoDBStorage(AbstractStorage):
def __init__(self, testing) -> None:
self.logger = logger.getChild(self.sid)

# MongoDB
try:
import pymongo
except ImportError: # pragma: no cover
raise ImportError(
"Could not import pymongo, cannot use as a datastore backend"
)

self.client = pymongo.MongoClient(serverSelectionTimeoutMS=5000)
# Try to connect to the server to make sure that it's available
# If it isn't, it will raise pymongo.errors.ServerSelectionTimeoutError
Expand Down

0 comments on commit 2e999f0

Please sign in to comment.