Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backslash to database name if needed #521

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading