Skip to content

Commit

Permalink
backends: db: Avoid deprecated Table.count SQLAlchemy API.
Browse files Browse the repository at this point in the history
Fixes thinkle#1035.

* gourmet/backends/db.py (RecData.fetch_len): Use
the sqlalchemy.func.count selector to return the table length.
  • Loading branch information
Apteryks committed May 4, 2022
1 parent 8af29c8 commit 6c41b36
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gourmet/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6c41b36

Please sign in to comment.