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

improve ux when trying to open sqlite without protocol #800

Merged
Merged
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions optuna_dashboard/_storage_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os.path
from pathlib import Path
import re
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -58,11 +59,22 @@
return guess_storage_from_url(storage)


def _has_sqlite_suffix(storage_url: str) -> bool:
storage_path = Path(storage_url)
SQLITE_EXTENSIONS = (".db", ".sqlite3")
turbotimon marked this conversation as resolved.
Show resolved Hide resolved
return storage_path.suffix in SQLITE_EXTENSIONS


def guess_storage_from_url(storage_url: str) -> BaseStorage:
if storage_url.startswith("redis"):
return get_journal_redis_storage(storage_url)

if os.path.isfile(storage_url):
if _has_sqlite_suffix(storage_url):
raise ValueError(

Check warning on line 74 in optuna_dashboard/_storage_url.py

View check run for this annotation

Codecov / codecov/patch

optuna_dashboard/_storage_url.py#L74

Added line #L74 was not covered by tests
"It looks like you are trying to open a sqlite db. "
+ "Please make sure you specify the driver, e.g.: sqlite:///example.db"
)
return get_journal_file_storage(storage_url)

if rfc1738_pattern.match(storage_url) is not None:
Expand Down
Loading