From f8438376cc50c641a9c8bcee728d5bfb7b7b0cfa Mon Sep 17 00:00:00 2001 From: cloudyun888 <15502132060@163.com> Date: Wed, 22 Apr 2026 23:44:45 +0800 Subject: [PATCH] fix: return exact row counts from inspect --- datasette/cli.py | 1 + tests/test_cli.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/datasette/cli.py b/datasette/cli.py index 93aa22ef..0f6e9685 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -154,6 +154,7 @@ async def inspect_(files, sqlite_extensions): app = Datasette([], immutables=files, sqlite_extensions=sqlite_extensions) data = {} for name, database in app.databases.items(): + database.count_limit = 10**10 counts = await database.table_counts(limit=3600 * 1000) data[name] = { "hash": database.hash, diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d3a2b28..ba372191 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -46,6 +46,21 @@ def test_inspect_cli_writes_to_file(app_client): assert ["fixtures"] == list(data.keys()) +def test_inspect_cli_returns_exact_counts_for_large_tables(tmp_path): + db_path = tmp_path / "large.db" + conn = sqlite3.connect(db_path) + conn.execute("create table t(id integer primary key)") + conn.executemany("insert into t(id) values (?)", [(i,) for i in range(10002)]) + conn.commit() + conn.close() + + runner = CliRunner() + result = runner.invoke(cli, ["inspect", str(db_path)]) + assert result.exit_code == 0, result.output + data = json.loads(result.output) + assert data["large"]["tables"]["t"]["count"] == 10002 + + def test_serve_with_inspect_file_prepopulates_table_counts_cache(): inspect_data = {"fixtures": {"tables": {"hithere": {"count": 44}}}} with make_app_client(inspect_data=inspect_data, is_immutable=True) as client: