Skip to content

Create parent directories for SQLite database files#19205

Merged
harupy merged 1 commit intomlflow:masterfrom
harupy:create-sqlite-parent-dirs
Dec 4, 2025
Merged

Create parent directories for SQLite database files#19205
harupy merged 1 commit intomlflow:masterfrom
harupy:create-sqlite-parent-dirs

Conversation

@harupy
Copy link
Member

@harupy harupy commented Dec 4, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19205/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19205/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19205/merge

What changes are proposed in this pull request?

When using a SQLite URI like sqlite:///path/to/nested/dir/mlflow.db, the parent directories are now automatically created if they don't exist. This prevents errors when the user specifies a path to a non-existent directory.

The logic is added to create_sqlalchemy_engine_with_retry so all SQLite database connections benefit from this fix automatically.

In-memory databases (:memory:) and empty paths are correctly skipped.

How is this PR tested?

  • New unit/integration tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.

Release Notes

Is this a user-facing change?

  • Yes. Give a description of this change to be included in the release notes for MLflow users.

Automatically create parent directories for SQLite database files when they don't exist.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry

How should the PR be classified in the release notes? Choose one:

  • rn/feature - A new user-facing feature worth mentioning in the release notes

Should this PR be included in the next patch release?

  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 4, 2025 06:00
@github-actions github-actions bot added area/model-registry Model registry, model registry APIs, and the fluent client calls for model registry area/tracking Tracking service, tracking client APIs, autologging rn/feature Mention under Features in Changelogs. labels Dec 4, 2025
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy force-pushed the create-sqlite-parent-dirs branch from 2e396ee to e0d7525 Compare December 4, 2025 06:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds automatic creation of parent directories for SQLite database files when using nested paths in database URIs like sqlite:///path/to/nested/dir/mlflow.db. The logic is integrated into create_sqlalchemy_engine_with_retry to apply to all SQLite connections.

Key Changes:

  • Added _make_parent_dirs_if_sqlite() helper function to create parent directories for SQLite database files
  • Integrated the helper into create_sqlalchemy_engine_with_retry() to automatically create directories before engine creation
  • Added unit tests covering nested paths, in-memory databases, and non-SQLite URIs

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
mlflow/store/db/utils.py Adds _make_parent_dirs_if_sqlite() function and integrates it into create_sqlalchemy_engine_with_retry() to create parent directories before SQLite database creation
tests/store/db/test_utils.py Adds three test cases covering the main functionality (nested directory creation), in-memory database handling, and non-SQLite URI handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def _make_parent_dirs_if_sqlite(db_uri: str) -> None:
"""Create parent directories for SQLite database file if they don't exist."""
if not db_uri.startswith("sqlite:///"):
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function only checks for sqlite:/// (three slashes), which is the Unix/Linux format. On Windows, SQLite URIs use sqlite:// (two slashes) for absolute paths, as seen in mlflow/utils/file_utils.py:493. This means the function will not create parent directories for SQLite databases on Windows.

Consider using sqlite: as the prefix check and properly parsing the path based on the platform, or use a more robust URI parsing approach like:

if not db_uri.startswith("sqlite:"):
    return
db_path = db_uri.removeprefix("sqlite://")
# Remove leading slash for proper path handling
db_path = db_path.lstrip("/")

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Documentation preview for e0d7525 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Copy link
Collaborator

@serena-ruan serena-ruan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions github-actions bot added the v3.7.0 label Dec 4, 2025
@harupy harupy added this pull request to the merge queue Dec 4, 2025
Merged via the queue into mlflow:master with commit 2ca4246 Dec 4, 2025
59 of 61 checks passed
@harupy harupy deleted the create-sqlite-parent-dirs branch December 4, 2025 11:55
BenWilson2 pushed a commit to BenWilson2/mlflow that referenced this pull request Dec 4, 2025
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
BenWilson2 pushed a commit that referenced this pull request Dec 4, 2025
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/model-registry Model registry, model registry APIs, and the fluent client calls for model registry area/tracking Tracking service, tracking client APIs, autologging rn/feature Mention under Features in Changelogs. team-review Trigger a team review request v3.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants