Q:

Using for loops in sqlalchemy query

So i wanna use a for loop in a query and pull results if a record's field is equal to an object's property (in a list of objects) how do i do that?  This is my code:
you = session.query(Users).filter_by(id=login_session['userid']).first()

friends = session.query(Friends).filter_by(user_id=login_session['userid']).all()

dashboard = session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()

but then i get this:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/pearadox6/travellr/app.py", line 423, in feed
    dashboard = session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()
  File "<string>", line 1, in <lambda>
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 51, in generate
    fn(self, *args[1:], **kw)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1216, in filter
    criterion = expression._literal_as_text(criterion)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/expression.py", line 1521, in _literal_as_text
    "SQL expression object or string expected." 
ArgumentError: SQL expression object or string expected. 

Why? 

A:

Why? 

Because you can't pass a generator object as an argument for filter:
session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()

Use in_ with a list instead:
session.query(Markers).filter(Markers.owner.in_([f.friend_id for f in friends)]).all()

