From 80743e72a3bab485437ac29d11f1d5a1d039bb77 Mon Sep 17 00:00:00 2001 From: Oleg Ovcharuk Date: Mon, 18 Nov 2024 17:40:44 +0300 Subject: [PATCH] Add backslash to database name if needed --- ydb/driver.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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