Skip to content

Commit 16775d1

Browse files
committed
bugfix: Throw upstream error when invalid token
1 parent e15fddd commit 16775d1

File tree

1 file changed

+24
-13
lines changed
  • src/backend/base/langflow/components/vectorstores

1 file changed

+24
-13
lines changed

src/backend/base/langflow/components/vectorstores/astradb.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,9 @@ def _initialize_database_options(self):
447447
}
448448
for name, info in self.get_database_list().items()
449449
]
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
454453

455454
def _initialize_collection_options(self, api_endpoint: str | None = None):
456455
database = self.get_database_object(api_endpoint=api_endpoint)
@@ -483,25 +482,37 @@ def _initialize_collection_options(self, api_endpoint: str | None = None):
483482

484483
return []
485484

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+
486499
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):
487500
# TODO: Remove special astra flags when overlays are out
488501
# TODO: Better targeting of this field
489502
dslf = os.getenv("AWS_EXECUTION_ENV") == "AWS_ECS_FARGATE"
490503

504+
# If the token has not been provided, simply return
505+
if not self.token:
506+
return self.reset_build_config(build_config)
507+
491508
# Refresh the database name options
492509
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+
493513
# Get the list of options we have based on the token provided
494514
database_options = self._initialize_database_options()
495515

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-
505516
# If we retrieved options based on the token, show the dropdown
506517
build_config["api_endpoint"]["options"] = [db["name"] for db in database_options]
507518
build_config["api_endpoint"]["options_metadata"] = [

0 commit comments

Comments
 (0)