From 50d2d1aac985f440b36e6847e3ddacb4a6bf4d4b Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 1 May 2019 17:54:48 -0700 Subject: [PATCH] Fixed bug where metadata.json hidden tables were ignored --- datasette/app.py | 14 ++++++++++++++ datasette/views/index.py | 7 ------- tests/test_api.py | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index bd950b87..12abaab9 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -205,6 +205,20 @@ class ConnectedDatabase: """) ).rows ] + # Add any from metadata.json + db_metadata = self.ds.metadata(database=self.name) + if "tables" in db_metadata: + hidden_tables += [ + t for t in db_metadata["tables"] if db_metadata["tables"][t].get("hidden") + ] + # Also mark as hidden any tables which start with the name of a hidden table + # e.g. "searchable_fts" implies "searchable_fts_content" should be hidden + for table_name in await self.table_names(): + for hidden_table in hidden_tables[:]: + if table_name.startswith(hidden_table): + hidden_tables.append(table_name) + continue + return hidden_tables async def view_names(self): diff --git a/datasette/views/index.py b/datasette/views/index.py index 6f42d152..b23f3888 100644 --- a/datasette/views/index.py +++ b/datasette/views/index.py @@ -41,13 +41,6 @@ class IndexView(RenderMixin): name, lambda conn: detect_fts(conn, table) ), } - # Also mark as hidden any tables which start with the name of a hidden table - # e.g. "searchable_fts" implies "searchable_fts_content" should be hidden - for t in tables.keys(): - for hidden_table in hidden_table_names: - if t == hidden_table or t.startswith(hidden_table): - tables[t]["hidden"] = True - continue hidden_tables = [t for t in tables.values() if t["hidden"]] databases.append({ diff --git a/tests/test_api.py b/tests/test_api.py index 26819507..bf8b87b9 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -26,8 +26,10 @@ def test_homepage(app_client): assert d["tables_count"] == 25 assert len(d["tables_truncated"]) == 5 assert d["tables_more"] is True - assert d["hidden_table_rows_sum"] == 5 - assert d["hidden_tables_count"] == 4 + # 4 hidden FTS tables + no_primary_key (hidden in metadata) + assert d["hidden_tables_count"] == 5 + # 201 in no_primary_key, plus 5 in other hidden tables: + assert d["hidden_table_rows_sum"] == 206 assert d["views_count"] == 4