table_config instead of table_metadata (#2257)

Table configuration that was incorrectly placed in metadata is now treated as if it was in config.

New await datasette.table_config() method.

Closes #2247
This commit is contained in:
Simon Willison 2024-02-06 21:57:09 -08:00 committed by GitHub
commit 60c6692f68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 175 additions and 30 deletions

View file

@ -75,6 +75,7 @@ from .utils import (
format_bytes,
module_from_path,
move_plugins,
move_table_config,
parse_metadata,
resolve_env_secrets,
resolve_routes,
@ -346,7 +347,9 @@ class Datasette:
# Move any "plugins" settings from metadata to config - updates them in place
metadata = metadata or {}
config = config or {}
move_plugins(metadata, config)
metadata, config = move_plugins(metadata, config)
# Now migrate any known table configuration settings over as well
metadata, config = move_table_config(metadata, config)
self._metadata_local = metadata or {}
self.sqlite_extensions = []
@ -1202,10 +1205,11 @@ class Datasette:
def _actor(self, request):
return {"actor": request.actor}
async def table_config(self, database, table):
"""Fetch table-specific metadata."""
async def table_config(self, database: str, table: str) -> dict:
"""Return dictionary of configuration for specified table"""
return (
(self.metadata("databases") or {})
(self.config or {})
.get("databases", {})
.get(database, {})
.get("tables", {})
.get(table, {})