Query the zip codes with select()
All checks were successful
CI / Tests (test-types) (push) Successful in 1m42s
CI / Tests (test) (push) Successful in 1m46s
CI / Tests (test-with-3.15) (push) Successful in 1m48s
CI / Lint (push) Successful in 2m1s

The raw SQL failed in PostgreSQL
because it referenced the aliased table by its full name.

`select()` fixes that, matches the rest of the module,
and drops the `noqa`.
This commit is contained in:
Alexander Hess 2026-12-04 10:07:10 +01:00
commit 07440785ab
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -233,19 +233,11 @@ class City(meta.Base):
"""
# First, create a color map with distinct colors for each zip code
all_zip_codes = sorted(
row[0]
for row in db.session.execute(
sa.text(
f"""
SELECT DISTINCT
{pkg_config.CLEAN_SCHEMA}.addresses.zip_code
FROM
{pkg_config.CLEAN_SCHEMA}.addresses AS addresses
WHERE
{pkg_config.CLEAN_SCHEMA}.addresses.city_id = {self.id};
""", # noqa:S608
),
)
db.session.scalars(
sa.select(db.Address.zip_code)
.where(db.Address.city == self)
.distinct(),
),
)
cmap = utils.make_random_cmap(len(all_zip_codes), bright=False)
colors = {