From 6c41b36f88945ca282d46db21c8b5adb97128cfb Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Wed, 4 May 2022 11:46:26 -0400 Subject: [PATCH] backends: db: Avoid deprecated Table.count SQLAlchemy API. Fixes #1035. * gourmet/backends/db.py (RecData.fetch_len): Use the sqlalchemy.func.count selector to return the table length. --- gourmet/backends/db.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gourmet/backends/db.py b/gourmet/backends/db.py index faa6a57a4..7e6d2bc63 100644 --- a/gourmet/backends/db.py +++ b/gourmet/backends/db.py @@ -773,9 +773,11 @@ def fetch_len (self, table, **criteria): """Return the number of rows in table that match criteria """ if criteria: - return table.count(*make_simple_select_arg(criteria,table)).execute().fetchone()[0] + return sqlalchemy.select( + sqlalchemy.func.count(criteria)).select_from(table).scalar() else: - return table.count().execute().fetchone()[0] + return sqlalchemy.select( + sqlalchemy.func.count()).select_from(table).scalar() def fetch_join (self, table1, table2, col1, col2, column_names=None, sort_by=[], **criteria):