From bc2e3f439d8c7c185bb6972f735c251f16d0b8e4 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Tue, 1 Dec 2026 23:50:44 +0100 Subject: [PATCH] Count with `.scalar_one()` in `velofy.console.gridify` A `COUNT` always returns exactly one row; `.scalar_one()` is typed as `int` and is used for all other counts as well. --- src/velofy/console/gridify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/velofy/console/gridify.py b/src/velofy/console/gridify.py index 64f5311..56f993e 100644 --- a/src/velofy/console/gridify.py +++ b/src/velofy/console/gridify.py @@ -38,11 +38,11 @@ def gridify() -> None: # pragma: no cover note:b1f68d24 # Because the number of assigned addresses is the same across # different `side_length`s, we can take the last `grid` from the `city`. last_grid_id = grid.id # type: ignore[possibly-undefined] - n_assigned = db.session.scalar( + n_assigned = db.session.execute( sa.select(sa.func.count()) .select_from(db.AddressPixelAssociation) .where(db.AddressPixelAssociation.grid_id == last_grid_id), - ) + ).scalar_one() click.echo( f"=> Assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501 )