Skip to content

Commit

Permalink
Add backslash to database name if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvoleg committed Nov 18, 2024
1 parent e9d9ea2 commit 80743e7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ydb/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 80743e7

Please sign in to comment.