Skip to content

Commit 311b5b3

Browse files
fix: Correctly update reactive form on hosted instances (#6023)
* fix: Update reactive form on hosted dslf * [autofix.ci] apply automated fixes * Update astradb.py * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c007a5f commit 311b5b3

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
537537

538538
# Reload the list of collections and metadata associated
539539
collection_options = self._initialize_collection_options(
540-
api_endpoint=build_config["d_api_endpoint"]["value"]
540+
api_endpoint=build_config["d_api_endpoint"]["value"] if not dslf else None
541541
)
542542

543543
# If we have collections, show the dropdown
@@ -549,31 +549,34 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
549549
# Hide embedding model option if opriona_metadata provider is not null
550550
if field_name == "collection_name" and field_value:
551551
# Set the options for collection name to be the field value if its a new collection
552-
if not dslf and field_value not in build_config["collection_name"]["options"]:
553-
# Add the new collection to the list of options
554-
build_config["collection_name"]["options"].append(field_value)
555-
build_config["collection_name"]["options_metadata"].append(
556-
{"records": 0, "provider": None, "icon": "", "model": None}
557-
)
558-
559-
# Ensure that autodetect collection is set to False
560-
build_config["autodetect_collection"]["value"] = False
552+
if field_value not in build_config["collection_name"]["options"]:
553+
# If this is running in DSLF, we may need to initialize the options again
554+
if dslf:
555+
# Reload the list of collections and metadata associated
556+
collection_options = self._initialize_collection_options(
557+
api_endpoint=build_config["d_api_endpoint"]["value"] if not dslf else None
558+
)
559+
560+
# If we have collections, show the dropdown
561+
build_config["collection_name"]["options"] = [col["name"] for col in collection_options]
562+
build_config["collection_name"]["options_metadata"] = [
563+
{k: v for k, v in col.items() if k not in ["name"]} for col in collection_options
564+
]
565+
else:
566+
# Add the new collection to the list of options
567+
build_config["collection_name"]["options"].append(field_value)
568+
build_config["collection_name"]["options_metadata"].append(
569+
{"records": 0, "provider": None, "icon": "", "model": None}
570+
)
571+
572+
# Ensure that autodetect collection is set to False, since its a new collection
573+
build_config["autodetect_collection"]["value"] = False
561574
else:
562575
build_config["autodetect_collection"]["value"] = True
563576

564-
# Find location of the name in the options list
577+
# Find the position of the selected collection to align with metadata
565578
index_of_name = build_config["collection_name"]["options"].index(field_value)
566579

567-
# Return if not found
568-
if index_of_name == -1:
569-
return build_config
570-
571-
# Check if the number of records is 0
572-
if build_config["collection_name"]["options_metadata"][index_of_name]["records"] == 0:
573-
build_config["autodetect_collection"]["value"] = False
574-
else:
575-
build_config["autodetect_collection"]["value"] = True
576-
577580
# Get the provider value of the selected collection
578581
value_of_provider = build_config["collection_name"]["options_metadata"][index_of_name]["provider"]
579582

0 commit comments

Comments
 (0)