Reorder filters to fix SQLAlchemy error.