Rather than doing an `exists()` followed by a `values_list()` (two queries), it would be simpler to set `invalid_ids` to the distinct list of ids and check if it's not empty. `invalid_ids = set(assessments.values_list('id', flat=True).distinct())`.