Merge pull request #355 from tseaver/fix-354-connect_lancedb-w-relative-db_path
fix: pass absolute 'db_path' to 'lancedb.connect_async'
This commit is contained in:
commit
7828a8b05d
2 changed files with 25 additions and 2 deletions
|
|
@ -70,7 +70,7 @@ async def connect_lancedb(
|
||||||
else:
|
else:
|
||||||
if db_path is None:
|
if db_path is None:
|
||||||
raise ValueError("No lancedb.uri configured and no db_path provided")
|
raise ValueError("No lancedb.uri configured and no db_path provided")
|
||||||
return await lancedb.connect_async(db_path)
|
return await lancedb.connect_async(db_path.absolute())
|
||||||
|
|
||||||
|
|
||||||
class DocumentRecord(LanceModel):
|
class DocumentRecord(LanceModel):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,30 @@
|
||||||
|
import pathlib
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from haiku.rag.config import AppConfig
|
||||||
from haiku.rag.store import Store
|
from haiku.rag.store import Store
|
||||||
from haiku.rag.store.engine import get_database_stats
|
from haiku.rag.store.engine import connect_lancedb, get_database_stats
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("w_relative", [False, True])
|
||||||
|
@mock.patch("lancedb.connect_async")
|
||||||
|
async def test_connect_lancedb(ldbca, w_relative):
|
||||||
|
config = AppConfig(environment="testing")
|
||||||
|
relative_db_path = pathlib.Path("path/to/lancedb")
|
||||||
|
absolute_db_path = relative_db_path.absolute()
|
||||||
|
|
||||||
|
if w_relative:
|
||||||
|
db_path = relative_db_path
|
||||||
|
else:
|
||||||
|
db_path = absolute_db_path
|
||||||
|
|
||||||
|
found = await connect_lancedb(config, db_path)
|
||||||
|
|
||||||
|
assert found is ldbca.return_value
|
||||||
|
ldbca.assert_awaited_once_with(absolute_db_path)
|
||||||
|
|
||||||
|
|
||||||
class TestGetDatabaseStats:
|
class TestGetDatabaseStats:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue