1717import mongomock
1818import grpc
1919
20+ from graphql_service .resolver .exceptions import (
21+ GenomeNotFoundError ,
22+ FailedToConnectToGrpc ,
23+ )
24+
25+
2026from yagrc import reflector as yagrc_reflector
2127
28+
2229from common .utils import process_release_version
2330
2431logger = logging .getLogger (__name__ )
@@ -37,9 +44,10 @@ def __init__(self, config):
3744 self .config = config
3845 self .mongo_client = MongoDbClient .connect_mongo (self .config )
3946
40- def get_database_conn (self , grpc_model , uuid , force_grpc = False ):
47+ def get_database_conn (self , grpc_model , uuid ):
4148 grpc_response = None
42- chosen_db = self .config .get ("mongo_default_db" )
49+
50+ chosen_db = None
4351 # Try to connect to gRPC
4452 try :
4553 grpc_response = grpc_model .get_release_by_genome_uuid (uuid )
@@ -48,23 +56,21 @@ def get_database_conn(self, grpc_model, uuid, force_grpc=False):
4856 logger .debug (
4957 "[get_database_conn] Couldn't connect to gRPC Host: %s" , grpc_exp
5058 )
59+ raise FailedToConnectToGrpc (
60+ "Internal server error: Couldn't connect to gRPC Host"
61+ )
5162
52- if force_grpc :
63+ if grpc_response and grpc_response . release_version :
5364 chosen_db = process_release_version (grpc_response )
5465 else :
55- if grpc_response and grpc_response .release_version :
56- chosen_db = process_release_version (grpc_response )
57- else :
58- # chosen_db value will fall back to the default value, which is 'mongo_default_db' that is in the config
59- # if force_grpc is not True
60- logger .warning (
61- "[get_database_conn] Falling back to the default Mongo DB: '%s'" ,
62- chosen_db ,
63- )
64-
65- logger .debug ("[get_database_conn] Connected to '%s' MongoDB" , chosen_db )
66- data_database_connection = self .mongo_client [chosen_db ]
67- return data_database_connection
66+ logger .warning ("[get_database_conn] Release not found" )
67+ raise GenomeNotFoundError ({"genome_id" : uuid })
68+
69+ if chosen_db is not None :
70+ logger .debug ("[get_database_conn] Connected to '%s' MongoDB" , chosen_db )
71+ data_database_connection = self .mongo_client [chosen_db ]
72+ return data_database_connection
73+ raise GenomeNotFoundError ({"genome_id" : uuid })
6874
6975 @staticmethod
7076 def connect_mongo (config ):
0 commit comments