Skip to content

Commit

Permalink
add debug log messages in list_user_favorites func
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Feb 4, 2025
1 parent 7a5b354 commit 3e3673f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/biokbase/catalog/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pymongo import ASCENDING
from pymongo import DESCENDING
from pymongo import MongoClient
from pymongo.errors import ServerSelectionTimeoutError
from pymongo.errors import ConnectionFailure

'''
Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self, mongo_host, mongo_db, mongo_user, mongo_psswd, mongo_authMech
try:
self.mongo.server_info() # force a call to server
print("Connection successful!")
except ServerSelectionTimeoutError as e:
except ConnectionFailure as e:
error_msg = "Connot connect to Mongo server\n"
error_msg += "ERROR -- {}:\n{}".format(

Check warning on line 139 in lib/biokbase/catalog/db.py

View check run for this annotation

Codecov / codecov/patch

lib/biokbase/catalog/db.py#L137-L139

Added lines #L137 - L139 were not covered by tests
e, "".join(traceback.format_exception(None, e, e.__traceback__))
Expand Down Expand Up @@ -940,6 +940,12 @@ def remove_favorite(self, module_name, app_id, username):
return self._check_update_result(result)

def list_user_favorites(self, username):
try:
self.mongo.server_info()
print("MongoDB is connected in list_user_favorites().")
except ConnectionFailure as e:
print(f"MongoDB connection failed list_user_favorites(): {e}")

Check warning on line 947 in lib/biokbase/catalog/db.py

View check run for this annotation

Codecov / codecov/patch

lib/biokbase/catalog/db.py#L946-L947

Added lines #L946 - L947 were not covered by tests

query = {'user': username}
selection = {'_id': 0, 'module_name_lc': 1, 'id': 1, 'timestamp': 1}
return list(self.favorites.find(query, selection).sort('timestamp', DESCENDING))
Expand Down

0 comments on commit 3e3673f

Please sign in to comment.