Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 578ffc3

Browse files
committed
Support absolute paths for SQLite
This makes it compatible with dj-database-url [1]. 1: https://github.com/kennethreitz/dj-database-url#id6
1 parent 0aaa100 commit 578ffc3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

databases/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ def netloc(self) -> typing.Optional[str]:
351351

352352
@property
353353
def database(self) -> str:
354-
return self.components.path.lstrip("/")
354+
path = self.components.path
355+
if path[:1] == "/":
356+
return path[1:]
357+
return path
355358

356359
@property
357360
def options(self) -> dict:

tests/test_database_url.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ def test_replace_database_url_components():
5151
new = u.replace(database="test_" + u.database)
5252
assert new.database == "test_mydatabase"
5353
assert str(new) == "sqlite:///test_mydatabase"
54+
55+
u = DatabaseURL("sqlite:////absolute/path")
56+
assert u.database == "/absolute/path"
57+
new = u.replace(database=u.database + "_test")
58+
assert new.database == "/absolute/path_test"
59+
assert str(new) == "sqlite:////absolute/path_test"

0 commit comments

Comments
 (0)