code: def _merge_into_session(
      obj: Base,
      # pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
      encode_func: Callable,
      # pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
      decode_func: Callable,
      encode_args: Optional[Dict[str, Any]] = None,
      decode_args: Optional[Dict[str, Any]] = None,
      # pyre-fixme[24]: Generic type `Callable` expects 2 type parameters.
      modify_sqa: Optional[Callable] = None,
  ) -> SQABase:
      """Given a user-facing object (that may or may not correspond to an
      existing DB object), perform the following steps to either create or
      update the necessary DB objects, and ensure the user-facing object
      is annotated with the appropriate db_ids:
  
      1.  Encode the user-facing object `obj` to a sqa object `sqa`
      2.  If the `modify_sqa` argument is passed in, apply this to `sqa`
          before continuing
      3.  Merge `sqa` into the session
          Note: if `sqa` and its children contain ids, they will be merged into
          those corresponding DB objects. If not, new DB objects will be created.
      4. `session.merge` returns `new_sqa`, which is the same as `sqa` but
          but annotated ids.
      5. Decode `new_sqa` into a new user-facing object `new_obj`
      6. Copy db_ids from `new_obj` to the originally passed-in `obj`
      """
      sqa = encode_func(obj, **(encode_args or {}))
  
      if modify_sqa is not None:
          modify_sqa(sqa=sqa)
  
      with session_scope() as session:
          new_sqa = session.merge(sqa)
          session.flush()
  
      new_obj = decode_func(new_sqa, **(decode_args or {}))
      _copy_db_ids_if_possible(obj=obj, new_obj=new_obj)
  
      return new_sqa
  
imports: import os
  from logging import Logger
  from typing import Any, Callable, Dict, List, Optional, Sequence, Union
  from ax.core.base_trial import BaseTrial
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun
  from ax.core.metric import Metric
  from ax.core.outcome_constraint import ObjectiveThreshold, OutcomeConstraint
  from ax.core.runner import Runner
  from ax.exceptions.core import UserInputError
  from ax.exceptions.storage import SQADecodeError
  from ax.modelbridge.generation_strategy import GenerationStrategy
  from ax.storage.sqa_store.db import session_scope, SQABase
  from ax.storage.sqa_store.decoder import Decoder
  from ax.storage.sqa_store.encoder import Encoder
  from ax.storage.sqa_store.sqa_classes import SQAData, SQAGeneratorRun, SQAMetric, SQARunner, SQATrial
  from ax.storage.sqa_store.sqa_config import SQAConfig
  from ax.storage.sqa_store.utils import copy_db_ids
  from ax.utils.common.base import Base
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast, not_none
label_desc: Use image node_id 14 for calling a global function with example usage: _merge_into_session(obj, encode_func, decode_func, encode_args, decode_args, modify_sqa) and returns: new_sqa