Build the SQLite queue URL without reparsing the path
This commit is contained in:
parent
a04dc9445b
commit
73e8ac2dd6
2 changed files with 17 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.engine import make_url
|
from sqlalchemy.engine import URL, make_url
|
||||||
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
||||||
|
|
||||||
from haiku.rag.config.models import QueueConfig
|
from haiku.rag.config.models import QueueConfig
|
||||||
|
|
@ -25,7 +25,9 @@ def make_engine(config: QueueConfig) -> AsyncEngine:
|
||||||
else:
|
else:
|
||||||
path = config.path.expanduser().resolve()
|
path = config.path.expanduser().resolve()
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
url = make_url(f"sqlite+aiosqlite:///{path}")
|
# URL.create keeps the path literal — building a string and reparsing
|
||||||
|
# would treat `?`/`#` in the filename as query/fragment.
|
||||||
|
url = URL.create("sqlite+aiosqlite", database=str(path))
|
||||||
|
|
||||||
if url.get_backend_name() == "sqlite":
|
if url.get_backend_name() == "sqlite":
|
||||||
engine = create_async_engine(url, pool_size=1, max_overflow=0)
|
engine = create_async_engine(url, pool_size=1, max_overflow=0)
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,19 @@ async def test_open_queue_creates_file_and_schema(tmp_path):
|
||||||
await eng.dispose()
|
await eng.dispose()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_open_queue_handles_path_with_url_chars(tmp_path):
|
||||||
|
"""A `?` (or `#`) is a valid POSIX filename char but has URL meaning.
|
||||||
|
The queue must open the literal file, not a truncated one."""
|
||||||
|
path = tmp_path / "queue?weird.db"
|
||||||
|
eng = await open_queue(QueueConfig(path=path))
|
||||||
|
try:
|
||||||
|
assert path.exists()
|
||||||
|
assert not (tmp_path / "queue").exists()
|
||||||
|
finally:
|
||||||
|
await eng.dispose()
|
||||||
|
|
||||||
|
|
||||||
# --- enqueue ---
|
# --- enqueue ---
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue