From 7407d0aacc1cbc0fac3006475bcff454d9d1978e Mon Sep 17 00:00:00 2001 From: Oleg Ovcharuk Date: Wed, 4 Dec 2024 10:44:46 +0300 Subject: [PATCH] Add slash to DB name --- ydb_dbapi/connections.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ydb_dbapi/connections.py b/ydb_dbapi/connections.py index 8f45318..a127fa2 100644 --- a/ydb_dbapi/connections.py +++ b/ydb_dbapi/connections.py @@ -78,7 +78,7 @@ def __init__( protocol = protocol if protocol else "grpc" self.endpoint = f"{protocol}://{host}:{port}" self.credentials = prepare_credentials(credentials) - self.database = database + self.database = self._maybe_add_slash(database) self.table_path_prefix = ydb_table_path_prefix self.connection_kwargs: dict = kwargs @@ -161,6 +161,15 @@ def _get_client_settings(self) -> ydb.QueryClientSettings: .with_native_json_in_result_sets(False) ) + def _maybe_add_slash(self, database: str) -> str: + if not database: + return database + + if database.startswith("/"): + return database + + return f"/{database}" + class Connection(BaseConnection): _driver_cls = ydb.Driver