From 49a3d3dfc0e7e1a76ead4b931400976091ac10d6 Mon Sep 17 00:00:00 2001 From: agustin18 Date: Fri, 25 Sep 2026 18:55:08 +0000 Subject: [PATCH] Return top-level plugin config when fallback requested and table is None Fixes #2959 --- datasette/app.py | 2 +- tests/test_plugins.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/datasette/app.py b/datasette/app.py index 3e4c5acf..5900f1fe 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -1497,7 +1497,7 @@ class Datasette: # fallback to top-level if needed if db_plugin_config is None and fallback: - self._plugin_config_top(plugin_name) + return self._plugin_config_top(plugin_name) return db_plugin_config diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 1084d270..15933875 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -301,6 +301,34 @@ async def test_plugin_config(ds_client): assert None is ds_client.ds.plugin_config("unknown-plugin") +@pytest.mark.parametrize( + "database,table,fallback,expected", + [ + ("configured_db", None, True, {"setting": "top"}), + ("configured_db", None, False, None), + ("configured_db", "some_table", True, {"setting": "top"}), + ("configured_db", "some_table", False, None), + ], +) +def test_plugin_config_top_fallback_when_table_none( + database, table, fallback, expected +): + datasette = Datasette( + config={ + "plugins": {"test-plugin": {"setting": "top"}}, + "databases": { + "configured_db": {"description": "A database without plugin config"} + }, + } + ) + assert ( + datasette.plugin_config( + "test-plugin", database=database, table=table, fallback=fallback + ) + == expected + ) + + @pytest.mark.asyncio async def test_plugin_config_env(ds_client, monkeypatch): monkeypatch.setenv("FOO_ENV", "FROM_ENVIRONMENT")