I found out that SQLAlchemy translates
db.query(...).filter(A.id.in_(ids))
into
SELECT ... FROM a WHERE a.id != a.id
When I ran into this, it was because I was using an Enum type for one of my database table columns. When I changed it to a String, the problem went away. That's not a real solution, since I would have preferred an Enum, but it did avoid the problem.