Skip to content

Commit 419ca5e

Browse files
fix: Escape special characters in the Postgres password (feast-dev#4394)
* Apply fix Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com> * Add special characters to postgres online store test Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com> * Fix linting error Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com> --------- Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com>
1 parent 3a32e8a commit 419ca5e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

sdk/python/feast/infra/utils/postgres/connection_utils.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import psycopg
66
import pyarrow as pa
77
from psycopg import AsyncConnection, Connection
8+
from psycopg.conninfo import make_conninfo
89
from psycopg_pool import AsyncConnectionPool, ConnectionPool
910

1011
from feast.infra.utils.postgres.postgres_config import PostgreSQLConfig
@@ -55,13 +56,14 @@ async def _get_connection_pool_async(config: PostgreSQLConfig) -> AsyncConnectio
5556

5657
def _get_conninfo(config: PostgreSQLConfig) -> str:
5758
"""Get the `conninfo` argument required for connection objects."""
58-
return (
59-
f"postgresql://{config.user}"
60-
f":{config.password}"
61-
f"@{config.host}"
62-
f":{int(config.port)}"
63-
f"/{config.database}"
64-
)
59+
psycopg_config = {
60+
"user": config.user,
61+
"password": config.password,
62+
"host": config.host,
63+
"port": int(config.port),
64+
"dbname": config.database,
65+
}
66+
return make_conninfo(conninfo="", **psycopg_config)
6567

6668

6769
def _get_conn_kwargs(config: PostgreSQLConfig) -> Dict[str, Any]:

sdk/python/tests/integration/feature_repos/universal/online_store/postgres.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, project_name: str, **kwargs):
1616
self.container = PostgresContainer(
1717
"postgres:16",
1818
username="root",
19-
password="test",
19+
password="test!@#$%",
2020
dbname="test",
2121
).with_exposed_ports(5432)
2222

@@ -26,7 +26,7 @@ def create_online_store(self) -> Dict[str, str]:
2626
"host": "localhost",
2727
"type": "postgres",
2828
"user": "root",
29-
"password": "test",
29+
"password": "test!@#$%",
3030
"database": "test",
3131
"port": self.container.get_exposed_port(5432),
3232
}
@@ -42,7 +42,7 @@ def __init__(self, project_name: str, **kwargs):
4242
self.container = (
4343
DockerContainer("pgvector/pgvector:pg16")
4444
.with_env("POSTGRES_USER", "root")
45-
.with_env("POSTGRES_PASSWORD", "test")
45+
.with_env("POSTGRES_PASSWORD", "test!@#$%")
4646
.with_env("POSTGRES_DB", "test")
4747
.with_exposed_ports(5432)
4848
.with_volume_mapping(
@@ -65,7 +65,7 @@ def create_online_store(self) -> Dict[str, Any]:
6565
"host": "localhost",
6666
"type": "postgres",
6767
"user": "root",
68-
"password": "test",
68+
"password": "test!@#$%",
6969
"database": "test",
7070
"pgvector_enabled": True,
7171
"vector_len": 2,

0 commit comments

Comments
 (0)