I'm working on a FastAPI project and I'm using SQLAlchemy to map the data to the API. I swear this problem started randomly as I've reverted back to my MVP code (bookmarked so I can always roll back to working code), and it still doesn't work. My situation is this, I'm trying to query the database to get the record count and then offset/limit and paginate. Here is my broken code: query = db.query(query_class) total_items = query.count().scalar() This returns an error int() argument must be a string, a bytes-like object or a real number, not 'NoneType' which tells me that count is likely None. Now obviously I can query the dataset and see there are records. In fact I can even do this: total_items = len(db.query(query_class).all()) Now can someone enlighten me on what I'm doing wrong here? Continue reading...