Skip to content

Commit

Permalink
Fixes for Datasette < 1.0
Browse files Browse the repository at this point in the history
Closes #29
  • Loading branch information
simonw authored Nov 28, 2023
1 parent 00a4bad commit a2526cb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
datasette-version: ["<1.0", ">=1.0a7"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -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
8 changes: 6 additions & 2 deletions datasette_enrichments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ 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()
if "count" in filtered_data:
row_count = filtered_data["count"]
else:
row_count = filtered_data["filtered_table_rows_count"]
await db.execute_write(CREATE_JOB_TABLE_SQL)

def _insert(conn):
Expand Down Expand Up @@ -189,7 +193,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:
Expand Down
14 changes: 13 additions & 1 deletion datasette_enrichments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit a2526cb

Please sign in to comment.