gourmet icon indicating copy to clipboard operation
gourmet copied to clipboard

Not compatible with SQLAlchemy >= 1.4.

Open apteryks opened this issue 3 years ago • 2 comments

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 avatar May 04 '22 14:05 apteryks

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

apteryks avatar May 04 '22 14:05 apteryks

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.

apteryks avatar May 04 '22 14:05 apteryks