From 80f5914abf0493661471bb26cbcd45c692c076c5 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Thu, 11 Jan 2024 14:25:00 +0700
Subject: [PATCH] fix: raise exception if PG_CONNECTION_STRING is empty
 (generated value)

---
 .../components/vectordbs/python/pg/utils.py          | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/packages/create-llama/templates/components/vectordbs/python/pg/utils.py b/packages/create-llama/templates/components/vectordbs/python/pg/utils.py
index 4453d13ec..808fda2c6 100644
--- a/packages/create-llama/templates/components/vectordbs/python/pg/utils.py
+++ b/packages/create-llama/templates/components/vectordbs/python/pg/utils.py
@@ -6,18 +6,22 @@ from app.engine.constants import PGVECTOR_SCHEMA, PGVECTOR_TABLE
 
 def init_pg_vector_store_from_env():
     original_conn_string = os.environ.get("PG_CONNECTION_STRING")
-    if original_conn_string is None:
+    if original_conn_string is None or original_conn_string == "":
         raise ValueError("PG_CONNECTION_STRING environment variable is not set.")
 
     # The PGVectorStore requires both two connection strings, one for psycopg2 and one for asyncpg
     # Update the configured scheme with the psycopg2 and asyncpg schemes
     original_scheme = urlparse(original_conn_string).scheme + "://"
-    conn_string = original_conn_string.replace(original_scheme, "postgresql+psycopg2://")
-    async_conn_string = original_conn_string.replace(original_scheme, "postgresql+asyncpg://")
+    conn_string = original_conn_string.replace(
+        original_scheme, "postgresql+psycopg2://"
+    )
+    async_conn_string = original_conn_string.replace(
+        original_scheme, "postgresql+asyncpg://"
+    )
 
     return PGVectorStore(
         connection_string=conn_string,
         async_connection_string=async_conn_string,
         schema_name=PGVECTOR_SCHEMA,
-        table_name=PGVECTOR_TABLE
+        table_name=PGVECTOR_TABLE,
     )
-- 
GitLab