thinkle / gourmet

Gourmet Recipe Manager
GNU General Public License v2.0
341 stars 141 forks source link

Not compatible with SQLAlchemy >= 1.4. #1035

Open Apteryks opened 2 years ago

Apteryks commented 2 years ago

When attempting to run the test suite, I get:

self = <gourmet.backends.db.RecData object at 0x7f991c503af0>
table = Table('keylookup', MetaData(bind=Engine(sqlite:////home/maxim/.gourmet/recipes.db)), Column('id', Integer(), table=<ke...=<keylookup>), Column('ingkey', Text(), table=<keylookup>), Column('count', Integer(), table=<keylookup>), schema=None)
criteria = {}

    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]
E           AttributeError: 'Table' object has no attribute 'count'

gourmet/backends/db.py:778: AttributeError

Steps to Reproduce

  1. Run the tests as the CI, making sure SQLAlchemy is at >= 1.4.

Expected Behavior

Tests should pass.

Current Behavior

Test fails with AttributeError: 'Table' object has no attribute 'count' errors.

Possible Solution

Update code to not use the deprecated 'count' SQLAlchemy Table attribute.

Environment

Guix System with Python 3.9.9, using the latest commit of Gourmet.

Apteryks commented 2 years ago

Note: a similar issue exists for gourmand: https://github.com/GourmandRecipeManager/gourmand/issues/79.

Apteryks commented 2 years ago

The solution is provided here: https://github.com/sqlalchemy/sqlalchemy/issues/6053#issuecomment-799833451

the Table.count() method has been deprecated since 2016 and has been removed in 1.4, so rdf-alchemy will need to adjust this code to use an explicit select(func.count()).select_from(table) instead.