From 07440785ab192c74e6b866ee8e631b3d858e5262 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Fri, 4 Dec 2026 10:07:10 +0100 Subject: [PATCH] Query the zip codes with `select()` 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`. --- src/velofy/db/cities.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/velofy/db/cities.py b/src/velofy/db/cities.py index a779efc..930701d 100644 --- a/src/velofy/db/cities.py +++ b/src/velofy/db/cities.py @@ -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 = {