﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37521	"SQLite backend creates a ""file:"" directory tree for URI database names"	Mariano Ignacio Baragiola	Mariano Ignacio Baragiola	"The SQLite backend always connects with `uri=True`, so a `NAME` that starts with `file:` is a SQLite URI. Since 2f7f30c320 (#36496), `DatabaseWrapper.get_new_connection()` treats the name as a path and runs `Path(name).parent.mkdir(parents=True)` before it connects. For a URI name this creates a `file:` directory tree in the current working directory. If that directory is read-only, the connection fails.

Reproduction (an existing database, read-only working directory):

{{{
#!python
DATABASES = {
    ""default"": {
        ""ENGINE"": ""django.db.backends.sqlite3"",
        ""NAME"": ""file:/srv/data/app.sqlite3?mode=ro"",
    }
}
}}}

{{{
#!python
from django.db import connection
connection.cursor().execute(""SELECT 1"")
}}}

Actual:
 * writable working directory: the query works, but Django creates the directories `file:/srv/data/` in the working directory.
 * read-only working directory: `django.db.utils.InterfaceError: Error creating path to SQLite database: [Errno 13] Permission denied: 'file:'.`

Expected: Django opens the database as in 6.1 and creates no directories.

Versions: main only. stable/6.1.x is not affected.

Regression in 2f7f30c320 (#36496, PR #22030).

Suggested fix: skip the parent directory creation when the name starts with `file:`. In-memory names (`:memory:`, `file:...?mode=memory`) already skip it.

AI disclosure: I found and reproduced this with Claude Code (Anthropic)."	Bug	assigned	Database layer (models, ORM)	dev	Release blocker				Unreviewed	0	0	0	0	0	0
