flask-sqlalchemy icon indicating copy to clipboard operation
flask-sqlalchemy copied to clipboard

Support __iter__ on Pagination instances.

Open rduplain opened this issue 13 years ago • 1 comments

I never remember to call .items, and I was just reminded of this when getting a new developer spun up. Instead of:

for obj in MyModel.query.paginate(1).items: pass

I expect:

for obj in MyModel.query.paginate(1): pass

... because SQLAlchemy's query API does this everywhere. This fails, because a Pagination instance is not iterable.

rduplain avatar Feb 01 '12 20:02 rduplain

Current discussion on #pocoo irc: no harm in making it iterable, but at that point you might just use .offset().limit() on the SQLAlchemy query interface. If Pagination is used generally, outside of a SQL context, then an iterable interface would be more useful.

rduplain avatar Feb 01 '12 22:02 rduplain

fixed in #1087

davidism avatar Sep 18 '22 17:09 davidism