Faceting the infinity fixture emits invalid JSON in facet_results
Faceting the committed infinity fixture returns HTTP 200 with bare -Infinity in facet_results, so a strict JSON client cannot parse the response. Row values in the same response are normalized to null; json_renderer() only applies remove_infinites() to data["rows"], leaving facet values outside that normalization.
Reproduction on main at 74f178cd12cb12aba05e182155935e39d783c5ee (Datasette 1.0a40, Python 3.12.12): save this as tests/test_infinity_facets_regression.py and run uv run pytest tests/test_infinity_facets_regression.py -q.
import json
import pytest
@pytest.mark.asyncio
async def test_infinity_facet_values_are_valid_json(ds_client):
response = await ds_client.get(
"/fixtures/infinity.json?_facet=value&_extra=facet_results"
)
assert response.status_code == 200
def reject_non_json_number(token):
raise ValueError(f"Non-JSON numeric literal: {token}")
data = json.loads(response.text, parse_constant=reject_non_json_number)
assert len(data["facet_results"]["results"]["value"]["results"]) == 3This fails with ValueError: Non-JSON numeric literal: -Infinity. The custom parse_constant callback makes Python reject the nonstandard numeric literals that its JSON decoder otherwise accepts.
The JSON API documentation promises that infinity values become None by default, with nonstandard literals available through the explicit _json_infinity=1 opt-in. Expected: the default response remains valid JSON when facet_results is requested, while the existing opt-in behavior remains available.
The existing uv run pytest tests/test_table_api.py -k infinity -q tests both pass; they exercise row output without facets. This reproduction uses the existing three-row fixture and makes no changes to its data.
Source: simonw/datasette