class_docstr: A generic way to store and retrieve arbitrary content or settings as a simple key/value store.
class_docstr_tok: ["A","generic","way","to","store","and","retrieve","arbitrary","content","or","settings","as","a","simple","key\/value","store","."]
docstr: Set a value for an Airflow Variable with a given Key.
  
  This operation overwrites an existing variable.
  
  :param key: Variable Key
  :param value: Value to set for the Variable
  :param description: Description of the Variable
  :param serialize_json: Serialize the value to a JSON string
docstr_tok: ["Set","a","value","for","an","Airflow","Variable","with","a","given","Key",".","This","operation","overwrites","an","existing","variable",".",":","param","key",":","Variable","Key",":","param","value",":","Value","to","set","for","the","Variable",":","param","description",":","Description","of","the","Variable",":","param","serialize_json",":","Serialize","the","value","to","a","JSON","string"]
code: def set(
      key: str,
      value: Any,
      description: str | None = None,
      serialize_json: bool = False,
      session: Session = None,
  ) -> None:
      """Set a value for an Airflow Variable with a given Key.
  
      This operation overwrites an existing variable.
  
      :param key: Variable Key
      :param value: Value to set for the Variable
      :param description: Description of the Variable
      :param serialize_json: Serialize the value to a JSON string
      """
      # check if the secret exists in the custom secrets' backend.
      Variable.check_for_write_conflict(key)
      if serialize_json:
          stored_value = json.dumps(value, indent=2)
      else:
          stored_value = str(value)
  
      Variable.delete(key, session=session)
      session.add(
          Variable(key=key, val=stored_value, description=description)
      )
      session.flush()
      # invalidate key in cache for faster propagation
      # we cannot save the value set because it's possible that it's shadowed by a custom backend
      # (see call to check_for_write_conflict above)
      SecretCache.invalidate_variable(key)
  
imports: from __future__ import annotations
  import json
  import logging
  from typing import TYPE_CHECKING, Any
  from sqlalchemy import Boolean, Column, Integer, String, Text, delete, select
  from sqlalchemy.dialects.mysql import MEDIUMTEXT
  from sqlalchemy.orm import declared_attr, reconstructor, synonym
  from airflow.api_internal.internal_api_call import internal_api_call
  from airflow.configuration import ensure_secrets_loaded
  from airflow.models.base import ID_LEN, Base
  from airflow.models.crypto import get_fernet
  from airflow.secrets.cache import SecretCache
  from airflow.secrets.metastore import MetastoreBackend
  from airflow.utils.log.logging_mixin import LoggingMixin
  from airflow.utils.log.secrets_masker import mask_secret
  from airflow.utils.session import provide_session
label_desc: Use image node_id 9 for calling the Variable obj's underlying member method code with example usage: obj.set(key, value, description, serialize_json, session) without return types