diff --git a/ydb/driver.py b/ydb/driver.py index 49bd223c..fa116fe3 100644 --- a/ydb/driver.py +++ b/ydb/driver.py @@ -3,6 +3,7 @@ import logging import os from typing import Any # noqa +from typing import Optional from . import credentials as credentials_impl, table, scheme, pool from . import tracing @@ -143,7 +144,7 @@ def __init__( """ self.endpoint = endpoint - self.database = database + self.database = self._maybe_add_slash(database) self.ca_cert = ca_cert self.channel_options = channel_options self.secure_channel = _utilities.is_secure_protocol(endpoint) @@ -169,7 +170,7 @@ def __init__( self.compression = compression def set_database(self, database): - self.database = database + self.database = self._maybe_add_slash(database) return self @classmethod @@ -206,6 +207,15 @@ def _update_attrs_by_kwargs(self, **kwargs): ) setattr(self, key, value) + def _maybe_add_slash(self, database: Optional[str]) -> Optional[str]: + if not database: + return database + + if database.startswith("/"): + return database + + return f"/{database}" + ConnectionParams = DriverConfig