File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed
short_term_memory_backends Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,12 @@ class ShortTermMemory(BaseModel):
137137 def model_post_init (self , __context : Any ) -> None :
138138 if self .db_url :
139139 logger .info ("The `db_url` is set, ignore `backend` option." )
140+ if self .db_url .count ("@" ) > 1 or self .db_url .count (":" ) > 2 :
141+ logger .warning (
142+ "Multiple `@` or `:` symbols detected in the database URL. "
143+ "Please encode `username` or `password` with `urllib.parse.quote_plus`. "
144+ "Examples: p@ssword→p%40ssword."
145+ )
140146 self ._session_service = DatabaseSessionService (db_url = self .db_url )
141147 else :
142148 if self .backend == "database" :
Original file line number Diff line number Diff line change 2121)
2222from pydantic import Field
2323from typing_extensions import override
24+ from urllib .parse import quote_plus
2425
2526import veadk .config # noqa E401
2627from veadk .configs .database_configs import MysqlConfig
@@ -33,7 +34,9 @@ class MysqlSTMBackend(BaseShortTermMemoryBackend):
3334 mysql_config : MysqlConfig = Field (default_factory = MysqlConfig )
3435
3536 def model_post_init (self , context : Any ) -> None :
36- self ._db_url = f"mysql+pymysql://{ self .mysql_config .user } :{ self .mysql_config .password } @{ self .mysql_config .host } /{ self .mysql_config .database } "
37+ encoded_username = quote_plus (self .mysql_config .user )
38+ encoded_password = quote_plus (self .mysql_config .password )
39+ self ._db_url = f"mysql+pymysql://{ encoded_username } :{ encoded_password } @{ self .mysql_config .host } /{ self .mysql_config .database } "
3740
3841 @cached_property
3942 @override
Original file line number Diff line number Diff line change 2222)
2323from pydantic import Field
2424from typing_extensions import override
25+ from urllib .parse import quote_plus
2526
2627import veadk .config # noqa E401
2728from veadk .configs .database_configs import PostgreSqlConfig
@@ -34,7 +35,9 @@ class PostgreSqlSTMBackend(BaseShortTermMemoryBackend):
3435 postgresql_config : PostgreSqlConfig = Field (default_factory = PostgreSqlConfig )
3536
3637 def model_post_init (self , context : Any ) -> None :
37- self ._db_url = f"postgresql://{ self .postgresql_config .user } :{ self .postgresql_config .password } @{ self .postgresql_config .host } :{ self .postgresql_config .port } /{ self .postgresql_config .database } "
38+ encoded_username = quote_plus (self .postgresql_config .user )
39+ encoded_password = quote_plus (self .postgresql_config .password )
40+ self ._db_url = f"postgresql://{ encoded_username } :{ encoded_password } @{ self .postgresql_config .host } :{ self .postgresql_config .port } /{ self .postgresql_config .database } "
3841 logger .debug (self ._db_url )
3942
4043 @cached_property
You can’t perform that action at this time.
0 commit comments