Ran into an issue while trying to build a plugin to render GeoJSON. I'm using pytest's tmp_path fixture, which is a pathlib.Path, to get a temporary database path. I was getting a weird error involving writes, but I was doing reads. Turns out it's the internal database trying to insert a Path where it wants a string.
My test looked like this:
@pytest.mark.asyncio
async def test_render_feature_collection(tmp_path):
database = tmp_path / "test.db"
datasette = Datasette([database])
# this will break with a path
await datasette.refresh_schemas()
# build a url
url = datasette.urls.table(database.stem, TABLE_NAME, format="geojson")
response = await datasette.client.get(url)
fc = response.json()
assert 200 == response.status_code
I only ran into this while running tests, because passing in database paths from the CLI uses strings, but it's a weird error and probably something other people have run into.
The fix is easy enough: Convert the path to a string and everything works. So this:
@pytest.mark.asyncio
async def test_render_feature_collection(tmp_path):
database = tmp_path / "test.db"
datasette = Datasette([str(database)])
# this is fine now
await datasette.refresh_schemas()
This could (probably, haven't tested) be fixed here by calling str(db.path) or by doing that conversion earlier.
Ran into an issue while trying to build a plugin to render GeoJSON. I'm using pytest's
tmp_pathfixture, which is apathlib.Path, to get a temporary database path. I was getting a weird error involving writes, but I was doing reads. Turns out it's the internal database trying to insert aPathwhere it wants a string.My test looked like this:
I only ran into this while running tests, because passing in database paths from the CLI uses strings, but it's a weird error and probably something other people have run into.
The fix is easy enough: Convert the path to a string and everything works. So this:
This could (probably, haven't tested) be fixed here by calling
str(db.path)or by doing that conversion earlier.