From aeabcb33cd484bd13735fa3f1bd4b58051909d46 Mon Sep 17 00:00:00 2001 From: Florian Olbrich Date: Mon, 7 Feb 2022 10:27:11 +0100 Subject: [PATCH] Updated db.py to comply to sqlalchemy 1.4, switched table.count() with func.count() --- src/gourmand/backends/db.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gourmand/backends/db.py b/src/gourmand/backends/db.py index 7f538c97..1c5228f3 100644 --- a/src/gourmand/backends/db.py +++ b/src/gourmand/backends/db.py @@ -9,7 +9,8 @@ import sqlalchemy.orm from gi.repository import Gtk from sqlalchemy import (Boolean, Column, Float, ForeignKey, Integer, - LargeBinary, Numeric, String, Table, Text, event, func) + LargeBinary, Numeric, String, Table, Text, + event, func, select) from sqlalchemy.sql import and_, case, or_ import gourmand.__version__ @@ -741,9 +742,16 @@ 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] - else: - return table.count().execute().fetchone()[0] + return select( + [func.count(list(table.primary_key.columns)[0])])\ + .where(*make_simple_select_arg(criteria,table))\ + .execute()\ + .fetchone()[0] + + return select( + [func.count(list(table.primary_key.columns)[0])])\ + .execute()\ + .fetchone()[0] def fetch_join (self, table1, table2, col1, col2, column_names=None, sort_by=None, **criteria):