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:
parent
185a37f7d4
commit
bc2e3f439d
1 changed files with 2 additions and 2 deletions
|
|
@ -38,11 +38,11 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
||||||
# Because the number of assigned addresses is the same across
|
# Because the number of assigned addresses is the same across
|
||||||
# different `side_length`s, we can take the last `grid` from the `city`.
|
# different `side_length`s, we can take the last `grid` from the `city`.
|
||||||
last_grid_id = grid.id # type: ignore[possibly-undefined]
|
last_grid_id = grid.id # type: ignore[possibly-undefined]
|
||||||
n_assigned = db.session.scalar(
|
n_assigned = db.session.execute(
|
||||||
sa.select(sa.func.count())
|
sa.select(sa.func.count())
|
||||||
.select_from(db.AddressPixelAssociation)
|
.select_from(db.AddressPixelAssociation)
|
||||||
.where(db.AddressPixelAssociation.grid_id == last_grid_id),
|
.where(db.AddressPixelAssociation.grid_id == last_grid_id),
|
||||||
)
|
).scalar_one()
|
||||||
click.echo(
|
click.echo(
|
||||||
f"=> Assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501
|
f"=> Assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue