diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8f4f78..56865aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,7 @@ jobs: strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + datasette-version: ["<1.0", ">=1.0"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -22,7 +23,8 @@ jobs: - name: Install dependencies run: | pip install '.[test]' + - name: Install specific version of Datasette + run: pip install "datasette${{ matrix.datasette-version }}" - name: Run tests run: | pytest - diff --git a/datasette_enrichments/__init__.py b/datasette_enrichments/__init__.py index 4ce467f..c70c4fc 100644 --- a/datasette_enrichments/__init__.py +++ b/datasette_enrichments/__init__.py @@ -127,7 +127,10 @@ async def enqueue( table_path = datasette.urls.table(db.name, table) response = await get_with_auth(datasette, table_path + ".json" + "?" + qs) - row_count = response.json()["count"] + filtered_data = response.json() + row_count = filtered_data.get( + "count", filtered_data["filtered_table_rows_count"] + ) await db.execute_write(CREATE_JOB_TABLE_SQL) def _insert(conn): @@ -189,7 +192,7 @@ async def run_enrichment(): qs = job["filter_querystring"] if next_cursor: qs += "&_next={}".format(next_cursor) - qs += "&_size={}".format(self.batch_size) + qs += "&_size={}&_shape=objects".format(self.batch_size) response = await get_with_auth(datasette, table_path + "?" + qs) rows = response.json()["rows"] if not rows: diff --git a/datasette_enrichments/views.py b/datasette_enrichments/views.py index b24233f..c74423f 100644 --- a/datasette_enrichments/views.py +++ b/datasette_enrichments/views.py @@ -36,7 +36,13 @@ async def enrichment_view(datasette, request): bits = [bit for bit in bits if bit[0] != "_sort"] # Add extras bits.extend( - [("_extra", "human_description_en"), ("_extra", "count"), ("_extra", "columns")] + [ + ("_extra", "human_description_en"), + ("_extra", "count"), + ("_extra", "columns"), + # This one makes it work for Datasette < 1.0: + ("_shape", "objects"), + ] ) # re-encode query_string = urllib.parse.urlencode(bits) @@ -46,6 +52,9 @@ async def enrichment_view(datasette, request): datasette.urls.table(database, table, "json") + "?" + query_string, ) ).json() + if "count" not in filtered_data: + # Fix for Datasette < 1.0 + filtered_data["count"] = filtered_data["filtered_table_rows_count"] # If an enrichment is selected, use that UI @@ -102,6 +111,9 @@ async def enrichment_picker(datasette, request): datasette.urls.table(database, table, "json") + "?" + query_string, ) filtered_data = response.json() + if "count" not in filtered_data: + # Fix for Datasette < 1.0 + filtered_data["count"] = filtered_data["filtered_table_rows_count"] enrichments_and_paths = [] for enrichment in enrichments.values(): diff --git a/setup.py b/setup.py index 9a578fa..09e355e 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def get_long_description(): version=VERSION, packages=["datasette_enrichments"], entry_points={"datasette": ["enrichments = datasette_enrichments"]}, - install_requires=["datasette>=1.0a7", "WTForms"], + install_requires=["datasette", "WTForms"], extras_require={ "test": ["pytest", "pytest-asyncio", "black", "ruff"], "docs": [