fix: Resolve connection issue with postgres when special characters are present
This commit is contained in:
parent
f48df27fc8
commit
6e5e79f434
2 changed files with 19 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
|
from sqlalchemy import URL
|
||||||
from .sqlalchemy.SqlAlchemyAdapter import SQLAlchemyAdapter
|
from .sqlalchemy.SqlAlchemyAdapter import SQLAlchemyAdapter
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from urllib.parse import quote_plus
|
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
|
|
@ -44,10 +44,16 @@ def create_relational_engine(
|
||||||
# Test if asyncpg is available
|
# Test if asyncpg is available
|
||||||
import asyncpg
|
import asyncpg
|
||||||
|
|
||||||
encoded_username = quote_plus(db_username)
|
# Handle special characters in username and password like # or @
|
||||||
encoded_password = quote_plus(db_password)
|
connection_string = URL.create(
|
||||||
|
"postgresql+asyncpg",
|
||||||
|
username=db_username,
|
||||||
|
password=db_password,
|
||||||
|
host=db_host,
|
||||||
|
port=int(db_port),
|
||||||
|
database=db_name,
|
||||||
|
)
|
||||||
|
|
||||||
connection_string = f"postgresql+asyncpg://{encoded_username}:{encoded_password}@{db_host}:{db_port}/{db_name}"
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"PostgreSQL dependencies are not installed. Please install with 'pip install cognee\"[postgres]\"' or 'pip install cognee\"[postgres-binary]\"' to use PostgreSQL functionality."
|
"PostgreSQL dependencies are not installed. Please install with 'pip install cognee\"[postgres]\"' or 'pip install cognee\"[postgres-binary]\"' to use PostgreSQL functionality."
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from sqlalchemy import URL
|
||||||
|
|
||||||
from .supported_databases import supported_databases
|
from .supported_databases import supported_databases
|
||||||
from .embeddings import get_embedding_engine
|
from .embeddings import get_embedding_engine
|
||||||
|
|
||||||
|
|
@ -61,8 +63,13 @@ def create_vector_engine(
|
||||||
if not (db_host and db_port and db_name and db_username and db_password):
|
if not (db_host and db_port and db_name and db_username and db_password):
|
||||||
raise EnvironmentError("Missing requred pgvector credentials!")
|
raise EnvironmentError("Missing requred pgvector credentials!")
|
||||||
|
|
||||||
connection_string: str = (
|
connection_string = URL.create(
|
||||||
f"postgresql+asyncpg://{db_username}:{db_password}@{db_host}:{db_port}/{db_name}"
|
"postgresql+asyncpg",
|
||||||
|
username=db_username,
|
||||||
|
password=db_password,
|
||||||
|
host=db_host,
|
||||||
|
port=int(db_port),
|
||||||
|
database=db_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue