Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/backend/base/langflow/components/vectorstores/astradb.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,14 @@
return build_config

def reset_database_list(self, build_config: dict):
# Get the list of options we have based on the token provided
database_options = self._initialize_database_options()
# Get names and metadata in a single sweep
names, metadata = self._get_and_parse_database_list()

# If we retrieved options based on the token, show the dropdown
build_config["api_endpoint"]["options"] = [db["name"] for db in database_options]
build_config["api_endpoint"]["options_metadata"] = [
{k: v for k, v in db.items() if k not in ["name"]} for db in database_options
]
# Set the lists directly without further processing
build_config["api_endpoint"]["options"] = names
build_config["api_endpoint"]["options_metadata"] = metadata

# Reset the selected database
# Reset the selected database to empty string
build_config["api_endpoint"]["value"] = ""

return build_config
Expand Down Expand Up @@ -806,3 +804,20 @@
"search_type": self._map_search_type(),
"search_kwargs": search_args,
}

def _get_and_parse_database_list(self):
try:
database_list = self.get_database_list()
names = []
metadata = []
for name, info in database_list.items():
names.append(name)
metadata.append(
{
"collections": info["collections"],
"api_endpoint": info["api_endpoint"],
}
)
return names, metadata

Check failure on line 821 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (TRY300)

src/backend/base/langflow/components/vectorstores/astradb.py:821:13: TRY300 Consider moving this statement to an `else` block
Comment on lines +811 to +821
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
names = []
metadata = []
for name, info in database_list.items():
names.append(name)
metadata.append(
{
"collections": info["collections"],
"api_endpoint": info["api_endpoint"],
}
)
return names, metadata
names = list(database_list.keys())
metadata = [
{"collections": info["collections"], "api_endpoint": info["api_endpoint"]}
for info in database_list.values()
]
except ValueError as ve:
raise ValueError(f"Error fetching database options: {ve}") from ve
raise ValueError(f"An unexpected error occurred: {e}") from e
@staticmethod
def _get_db_info(db, client, token, env_string):
api_endpoint = f"https://{db.info.id}-{db.info.region}.apps.astra{env_string}.datastax.com"
try:
collections_count = len(
list(
client.get_database(
api_endpoint=api_endpoint, token=token, keyspace=db.info.keyspace
).list_collection_names(keyspace=db.info.keyspace)
)
)
return db.info.name, {"api_endpoint": api_endpoint, "collections": collections_count}
except Exception:
return db.info.name, None

except Exception as e:
raise ValueError(f"Error fetching database options: {e}") from e

Check failure on line 823 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (TRY003)

src/backend/base/langflow/components/vectorstores/astradb.py:823:19: TRY003 Avoid specifying long messages outside the exception class

Check failure on line 823 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (EM102)

src/backend/base/langflow/components/vectorstores/astradb.py:823:30: EM102 Exception must not use an f-string literal, assign to variable first
Loading
Loading