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.
This commit is contained in:
Alexander Hess 2026-12-01 23:50:44 +01:00
commit bc2e3f439d
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -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
)