Skip to content

fix(storage): show human-readable error for uninitialized sqlite data…#1272

Open
TryingtobeingNikhil wants to merge 2 commits intooptuna:mainfrom
TryingtobeingNikhil:fix/empty-db-error-message
Open

fix(storage): show human-readable error for uninitialized sqlite data…#1272
TryingtobeingNikhil wants to merge 2 commits intooptuna:mainfrom
TryingtobeingNikhil:fix/empty-db-error-message

Conversation

@TryingtobeingNikhil
Copy link
Copy Markdown

What problem does this fix?

This fixes Issue #469 where launching the dashboard against an entirely empty or uninitialized SQLite database crashes the application with a confusing SQLAlchemy backend traceback rather than providing guidance to the user.

Root cause

When RDBStorage initializes with skip_table_creation=True, it throws an underlying sqlite3.OperationalError: no such table inside a generic wrapper exception because the Optuna schema does not exist yet.

What the fix does

It cleanly intercepts optuna.exceptions.StorageInternalError during get_rdb_storage() initialization, specifically inspects the __cause__ string for missing table warnings, and prints clear CLI instructions on how to initialize a database before exiting with code 1.

How I tested it

  • Manually ran optuna-dashboard sqlite:///empty_db.sqlite3 on a blank file and confirmed the new CLI instruction message appeared and exited immediately.
  • Manually generated a valid study database via a Python script and verified the dashboard booted correctly without hitting the new error trap.
  • Added a new pytest unit test simulating the empty-database crash and asserting the SystemExit code 1 behavior.
  • Ran the entire python_tests/ suite locally to ensure no other URL inference testing logic broke.

Edge cases considered

  • Inspected e.__cause__ because the true missing table detail gets wrapped deeply inside the SDK's generic exception structure.
  • Re-raised the unchanged StorageInternalError if it is triggered by an unrelated issue (e.g. data length violation) to avoid accidentally swallowing real bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant