@@ -447,10 +447,9 @@ def _initialize_database_options(self):
447
447
}
448
448
for name , info in self .get_database_list ().items ()
449
449
]
450
- except Exception as e : # noqa: BLE001
451
- self .log (f"Error fetching databases: { e } " )
452
-
453
- return []
450
+ except Exception as e :
451
+ msg = f"Error fetching database options: { e } "
452
+ raise ValueError (msg ) from e
454
453
455
454
def _initialize_collection_options (self , api_endpoint : str | None = None ):
456
455
database = self .get_database_object (api_endpoint = api_endpoint )
@@ -483,25 +482,37 @@ def _initialize_collection_options(self, api_endpoint: str | None = None):
483
482
484
483
return []
485
484
485
+ def reset_build_config (self , build_config : dict ):
486
+ # Reset the list of databases we have based on the token provided
487
+ build_config ["api_endpoint" ]["options" ] = []
488
+ build_config ["api_endpoint" ]["options_metadata" ] = []
489
+ build_config ["api_endpoint" ]["value" ] = ""
490
+ build_config ["api_endpoint" ]["name" ] = "Database"
491
+
492
+ # Reset the list of collections and metadata associated
493
+ build_config ["collection_name" ]["options" ] = []
494
+ build_config ["collection_name" ]["options_metadata" ] = []
495
+ build_config ["collection_name" ]["value" ] = ""
496
+
497
+ return build_config
498
+
486
499
def update_build_config (self , build_config : dict , field_value : str , field_name : str | None = None ):
487
500
# TODO: Remove special astra flags when overlays are out
488
501
# TODO: Better targeting of this field
489
502
dslf = os .getenv ("AWS_EXECUTION_ENV" ) == "AWS_ECS_FARGATE"
490
503
504
+ # If the token has not been provided, simply return
505
+ if not self .token :
506
+ return self .reset_build_config (build_config )
507
+
491
508
# Refresh the database name options
492
509
if not dslf and (field_name in ["token" , "environment" ] or not build_config ["api_endpoint" ]["options" ]):
510
+ # Reset the build config to ensure we are starting fresh
511
+ build_config = self .reset_build_config (build_config )
512
+
493
513
# Get the list of options we have based on the token provided
494
514
database_options = self ._initialize_database_options ()
495
515
496
- # Reset the collection values selected
497
- build_config ["collection_name" ]["options" ] = []
498
- build_config ["collection_name" ]["options_metadata" ] = []
499
- build_config ["collection_name" ]["value" ] = ""
500
-
501
- # Scenario #1: We have database options from the provided token
502
- build_config ["api_endpoint" ]["value" ] = ""
503
- build_config ["api_endpoint" ]["name" ] = "Database"
504
-
505
516
# If we retrieved options based on the token, show the dropdown
506
517
build_config ["api_endpoint" ]["options" ] = [db ["name" ] for db in database_options ]
507
518
build_config ["api_endpoint" ]["options_metadata" ] = [
0 commit comments