code: def _apply_range_filter(
      query: Select, key: ClauseElement, value_range: tuple[T, T]
  ) -> Select:
      gte_value, lte_value = value_range
      if gte_value is not None:
          query = query.where(key >= gte_value)
      if lte_value is not None:
          query = query.where(key <= lte_value)
      return query
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Any, Iterable, Sequence, TypeVar
  from flask import g
  from marshmallow import ValidationError
  from sqlalchemy import and_, or_, select
  from sqlalchemy.exc import MultipleResultsFound
  from sqlalchemy.orm import joinedload
  from airflow.api_connexion import security
  from airflow.api_connexion.endpoints.request_dict import get_json_request_dict
  from airflow.api_connexion.exceptions import BadRequest, NotFound, PermissionDenied
  from airflow.api_connexion.parameters import format_datetime, format_parameters
  from airflow.api_connexion.schemas.task_instance_schema import TaskInstanceCollection, TaskInstanceReferenceCollection, clear_task_instance_form, set_single_task_instance_state_form, set_task_instance_note_form_schema, set_task_instance_state_form, task_instance_batch_form, task_instance_collection_schema, task_instance_reference_collection_schema, task_instance_reference_schema, task_instance_schema
  from airflow.api_connexion.security import get_readable_dags
  from airflow.auth.managers.models.resource_details import DagAccessEntity, DagDetails
  from airflow.exceptions import TaskNotFound
  from airflow.models import SlaMiss
  from airflow.models.dagrun import DagRun
  from airflow.models.operator import needs_expansion
  from airflow.models.taskinstance import TaskInstance, clear_task_instances
  from airflow.utils.airflow_flask_app import get_airflow_app
  from airflow.utils.db import get_query_count
  from airflow.utils.session import NEW_SESSION, provide_session
  from airflow.utils.state import DagRunState, TaskInstanceState
  from airflow.www.extensions.init_auth_manager import get_auth_manager
label_desc: Use image node_id 6 for calling a global function with example usage: _apply_range_filter(query, key, value_range) and returns: query