code: def patch_connection(
      *,
      connection_id: str,
      update_mask: UpdateMask = None,
      session: Session = NEW_SESSION,
  ) -> APIResponse:
      """Update a connection entry."""
      try:
          data = connection_schema.load(request.json, partial=True)
      except ValidationError as err:
          # If validation get to here, it is extra field validation.
          raise BadRequest(detail=str(err.messages))
      non_update_fields = ["connection_id", "conn_id"]
      connection = session.scalar(
          select(Connection).filter_by(conn_id=connection_id).limit(1)
      )
      if connection is None:
          raise NotFound(
              "Connection not found",
              detail=f"The Connection with connection_id: `{connection_id}` was not found",
          )
      if data.get("conn_id") and connection.conn_id != data["conn_id"]:
          raise BadRequest(
              detail="The connection_id cannot be updated."
          )
      if update_mask:
          data = extract_update_mask_data(
              update_mask, non_update_fields, data
          )
      for key in data:
          setattr(connection, key, data[key])
      session.add(connection)
      session.commit()
      return connection_schema.dump(connection)
  
imports: from __future__ import annotations
  import os
  from http import HTTPStatus
  from typing import TYPE_CHECKING
  from connexion import NoContent
  from flask import Response, request
  from marshmallow import ValidationError
  from sqlalchemy import func, select
  from airflow.api_connexion import security
  from airflow.api_connexion.endpoints.update_mask import extract_update_mask_data
  from airflow.api_connexion.exceptions import AlreadyExists, BadRequest, NotFound
  from airflow.api_connexion.parameters import apply_sorting, check_limit, format_parameters
  from airflow.api_connexion.schemas.connection_schema import ConnectionCollection, connection_collection_schema, connection_schema, connection_test_schema
  from airflow.configuration import conf
  from airflow.models import Connection
  from airflow.secrets.environment_variables import CONN_ENV_PREFIX
  from airflow.security import permissions
  from airflow.utils import helpers
  from airflow.utils.log.action_logger import action_event_from_permission
  from airflow.utils.session import NEW_SESSION, provide_session
  from airflow.utils.strings import get_random_string
  from airflow.www.decorators import action_logging
label_desc: Use image node_id 4 for calling a global function with example usage: patch_connection() and returns: connection_schema