Skip to content

Commit

Permalink
Store null instead of 'None' in _internal database table, closes #1970
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 31, 2022
1 parent 234230e commit 8aa9cf6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 11 additions & 3 deletions datasette/app.py
@@ -1,4 +1,5 @@
import asyncio
from pydoc import plain
from typing import Sequence, Union, Tuple, Optional, Dict, Iterable
import asgi_csrf
import collections
Expand Down Expand Up @@ -415,12 +416,19 @@ async def _refresh_schemas(self):
# Compare schema versions to see if we should skip it
if schema_version == current_schema_versions.get(database_name):
continue
placeholders = "(?, ?, ?, ?)"
values = [database_name, str(db.path), db.is_memory, schema_version]
if db.path is None:
placeholders = "(?, null, ?, ?)"
values = [database_name, db.is_memory, schema_version]
await internal_db.execute_write(
"""
INSERT OR REPLACE INTO databases (database_name, path, is_memory, schema_version)
VALUES (?, ?, ?, ?)
""",
[database_name, str(db.path), db.is_memory, schema_version],
VALUES {}
""".format(
placeholders
),
values,
)
await populate_schema_tables(internal_db, db)

Expand Down
8 changes: 6 additions & 2 deletions tests/test_internal_db.py
Expand Up @@ -19,8 +19,12 @@ async def test_internal_databases(ds_client):
)
).json()
assert len(databases) == 2
assert databases[0]["database_name"] == "_internal"
assert databases[1]["database_name"] == "fixtures"
internal, fixtures = databases
assert internal["database_name"] == "_internal"
assert internal["is_memory"] == 1
assert internal["path"] is None
assert isinstance(internal["schema_version"], int)
assert fixtures["database_name"] == "fixtures"


@pytest.mark.asyncio
Expand Down

0 comments on commit 8aa9cf6

Please sign in to comment.