Skip to content

Commit e41621d

Browse files
authored
Merge pull request #521 from ydb-platform/fix_database_name
Add backslash to database name if needed
2 parents e9d9ea2 + 80743e7 commit e41621d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ydb/driver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
from typing import Any # noqa
6+
from typing import Optional
67

78
from . import credentials as credentials_impl, table, scheme, pool
89
from . import tracing
@@ -143,7 +144,7 @@ def __init__(
143144
144145
"""
145146
self.endpoint = endpoint
146-
self.database = database
147+
self.database = self._maybe_add_slash(database)
147148
self.ca_cert = ca_cert
148149
self.channel_options = channel_options
149150
self.secure_channel = _utilities.is_secure_protocol(endpoint)
@@ -169,7 +170,7 @@ def __init__(
169170
self.compression = compression
170171

171172
def set_database(self, database):
172-
self.database = database
173+
self.database = self._maybe_add_slash(database)
173174
return self
174175

175176
@classmethod
@@ -206,6 +207,15 @@ def _update_attrs_by_kwargs(self, **kwargs):
206207
)
207208
setattr(self, key, value)
208209

210+
def _maybe_add_slash(self, database: Optional[str]) -> Optional[str]:
211+
if not database:
212+
return database
213+
214+
if database.startswith("/"):
215+
return database
216+
217+
return f"/{database}"
218+
209219

210220
ConnectionParams = DriverConfig
211221

0 commit comments

Comments
 (0)