This commit is contained in:
ILYA Khalafi 2026-10-14 12:22:15 +03:30 • committed by GitHub
commit 9e3fee3c0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 1 deletions

View file

@ -1491,7 +1491,9 @@ class Datasette:
# fallback to db_config or top-level config, in that order, if needed
if table_plugin_config is None and fallback:
return db_plugin_config or self._plugin_config_top(plugin_name)
if db_plugin_config is not None:
return db_plugin_config
return self._plugin_config_top(plugin_name)
return table_plugin_config

View file

@ -302,6 +302,8 @@ If it cannot find the requested configuration at the table layer, it will fall b
In this case, the above code would return that configuration for ANY table within the ``sf-trees`` database.
An explicit empty dictionary at the database or table layer counts as configuration and prevents fallback to the next layer.
The plugin configuration could also be set at the top level of ``datasette.yaml``:
.. [[[cog

View file

@ -301,6 +301,47 @@ async def test_plugin_config(ds_client):
assert None is ds_client.ds.plugin_config("unknown-plugin")
@pytest.mark.parametrize(
"database_plugins,table_plugins,fallback,expected",
[
({"example": {}}, {}, True, {}),
({"example": {"setting": "database"}}, {}, True, {"setting": "database"}),
({}, {}, True, {"setting": "top"}),
({"example": None}, {}, True, {"setting": "top"}),
(
{"example": {}},
{"example": {"setting": "table"}},
True,
{"setting": "table"},
),
({"example": {"setting": "database"}}, {"example": {}}, True, {}),
({"example": {}}, {}, False, None),
({"example": {}}, {"example": {}}, False, {}),
],
)
def test_plugin_config_table_fallback_preserves_empty_database_config(
database_plugins, table_plugins, fallback, expected
):
datasette = Datasette(
config={
"plugins": {"example": {"setting": "top"}},
"databases": {
"example_db": {
"plugins": database_plugins,
"tables": {"items": {"plugins": table_plugins}},
}
},
}
)
assert (
datasette.plugin_config(
"example", database="example_db", table="items", fallback=fallback
)
== expected
)
@pytest.mark.asyncio
async def test_plugin_config_env(ds_client, monkeypatch):
monkeypatch.setenv("FOO_ENV", "FROM_ENVIRONMENT")