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`.
This commit is contained in:
parent
f025923d25
commit
07440785ab
1 changed files with 5 additions and 13 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue