def _environment_intersection(run, caseversion):
    """Intersection of run/caseversion environment IDs."""
    run_env_ids = set(
        run.environments.values_list("id", flat=True))
    case_env_ids = set(
        caseversion.environments.values_list("id", flat=True))
    return run_env_ids.intersection(case_env_ids)