Flask-SQLAlchemy different record count for .count() and .all() Flask-SQLAlchemy different record count for .count() and .all() flask flask

Flask-SQLAlchemy different record count for .count() and .all()


I think I may have fallen in the same problem. My query do multiple Joins, than the raw result can bring back multiple rows of the same primary key, each row is counted by .count(), however when you call .all() a distinct is applied on the primary key and only unique rows are fetched, than the number of records on .all() list is different from .count().

This should be equal:

query.distinct().count() == query.all()

Best regards


The function all() return a list and count() return a number...