# sqlalchemy 2.1.9 (MIT), harvested by tools/harvest_corpus.py
=== input
Copy the state of a given instance into a corresponding instance
        within this :class:`.Session`.

        .. container:: class_bases

            Proxied for the :class:`_orm.Session` class on
            behalf of the :class:`_orm.scoping.scoped_session` class.

        :meth:`.Session.merge` examines the primary key attributes of the
        source instance, and attempts to reconcile it with an instance of the
        same primary key in the session.   If not found locally, it attempts
        to load the object from the database based on primary key, and if
        none can be located, creates a new instance.  The state of each
        attribute on the source instance is then copied to the target
        instance.  The resulting target instance is then returned by the
        method; the original source instance is left unmodified, and
        un-associated with the :class:`.Session` if not already.

        This operation cascades to associated instances if the association is
        mapped with ``cascade="merge"``.

        See :ref:`unitofwork_merging` for a detailed discussion of merging.

        :param instance: Instance to be merged.
        :param load: Boolean, when False, :meth:`.merge` switches into
         a "high performance" mode which causes it to forego emitting history
         events as well as all database access.  This flag is used for
         cases such as transferring graphs of objects into a :class:`.Session`
         from a second level cache, or to transfer just-loaded objects
         into the :class:`.Session` owned by a worker thread or process
         without re-querying the database.

         The ``load=False`` use case adds the caveat that the given
         object has to be in a "clean" state, that is, has no pending changes
         to be flushed - even if the incoming object is detached from any
         :class:`.Session`.   This is so that when
         the merge operation populates local attributes and
         cascades to related objects and
         collections, the values can be "stamped" onto the
         target object as is, without generating any history or attribute
         events, and without the need to reconcile the incoming data with
         any existing related objects or collections that might not
         be loaded.  The resulting objects from ``load=False`` are always
         produced as "clean", so it is only appropriate that the given objects
         should be "clean" as well, else this suggests a mis-use of the
         method.
        :param options: optional sequence of loader options which will be
         applied to the :meth:`_orm.Session.get` method when the merge
         operation loads the existing version of the object from the database.

         .. versionadded:: 1.4.24


        .. seealso::

            :func:`.make_transient_to_detached` - provides for an alternative
            means of "merging" a single object into the :class:`.Session`

            :meth:`.Session.merge_all` - multiple instance version


        
=== parse rest
short_description: |
  Copy the state of a given instance into a corresponding instance
  within this :class:`.Session`.
long_description: |
  .. container:: class_bases
  
      Proxied for the :class:`_orm.Session` class on
      behalf of the :class:`_orm.scoping.scoped_session` class.
  
  :meth:`.Session.merge` examines the primary key attributes of the
  source instance, and attempts to reconcile it with an instance of the
  same primary key in the session.   If not found locally, it attempts
  to load the object from the database based on primary key, and if
  none can be located, creates a new instance.  The state of each
  attribute on the source instance is then copied to the target
  instance.  The resulting target instance is then returned by the
  method; the original source instance is left unmodified, and
  un-associated with the :class:`.Session` if not already.
  
  This operation cascades to associated instances if the association is
  mapped with ``cascade="merge"``.
  
  See :ref:`unitofwork_merging` for a detailed discussion of merging.
  
  .. seealso::
  
      :func:`.make_transient_to_detached` - provides for an alternative
      means of "merging" a single object into the :class:`.Session`
  
      :meth:`.Session.merge_all` - multiple instance version
blank_after_short_description: True
blank_after_long_description: True
style: rest
- DocstringParam
  description: 'Instance to be merged.'
  kind: param
  key: 'param'
  arg_name: 'instance'
  is_optional: False
- DocstringParam
  description: |
    Boolean, when False, :meth:`.merge` switches into
    a "high performance" mode which causes it to forego emitting history
    events as well as all database access.  This flag is used for
    cases such as transferring graphs of objects into a :class:`.Session`
    from a second level cache, or to transfer just-loaded objects
    into the :class:`.Session` owned by a worker thread or process
    without re-querying the database.
    
    The ``load=False`` use case adds the caveat that the given
    object has to be in a "clean" state, that is, has no pending changes
    to be flushed - even if the incoming object is detached from any
    :class:`.Session`.   This is so that when
    the merge operation populates local attributes and
    cascades to related objects and
    collections, the values can be "stamped" onto the
    target object as is, without generating any history or attribute
    events, and without the need to reconcile the incoming data with
    any existing related objects or collections that might not
    be loaded.  The resulting objects from ``load=False`` are always
    produced as "clean", so it is only appropriate that the given objects
    should be "clean" as well, else this suggests a mis-use of the
    method.
  kind: param
  key: 'param'
  arg_name: 'load'
  is_optional: False
- DocstringParam
  description: |
    optional sequence of loader options which will be
    applied to the :meth:`_orm.Session.get` method when the merge
    operation loads the existing version of the object from the database.
    
    .. versionadded:: 1.4.24
  kind: param
  key: 'param'
  arg_name: 'options'
  is_optional: False
=== detect
rest
=== compose rest
Copy the state of a given instance into a corresponding instance
within this :class:`.Session`.

.. container:: class_bases

    Proxied for the :class:`_orm.Session` class on
    behalf of the :class:`_orm.scoping.scoped_session` class.

:meth:`.Session.merge` examines the primary key attributes of the
source instance, and attempts to reconcile it with an instance of the
same primary key in the session.   If not found locally, it attempts
to load the object from the database based on primary key, and if
none can be located, creates a new instance.  The state of each
attribute on the source instance is then copied to the target
instance.  The resulting target instance is then returned by the
method; the original source instance is left unmodified, and
un-associated with the :class:`.Session` if not already.

This operation cascades to associated instances if the association is
mapped with ``cascade="merge"``.

See :ref:`unitofwork_merging` for a detailed discussion of merging.

.. seealso::

    :func:`.make_transient_to_detached` - provides for an alternative
    means of "merging" a single object into the :class:`.Session`

    :meth:`.Session.merge_all` - multiple instance version

:param instance: Instance to be merged.
:param load: Boolean, when False, :meth:`.merge` switches into
    a "high performance" mode which causes it to forego emitting history
    events as well as all database access.  This flag is used for
    cases such as transferring graphs of objects into a :class:`.Session`
    from a second level cache, or to transfer just-loaded objects
    into the :class:`.Session` owned by a worker thread or process
    without re-querying the database.

    The ``load=False`` use case adds the caveat that the given
    object has to be in a "clean" state, that is, has no pending changes
    to be flushed - even if the incoming object is detached from any
    :class:`.Session`.   This is so that when
    the merge operation populates local attributes and
    cascades to related objects and
    collections, the values can be "stamped" onto the
    target object as is, without generating any history or attribute
    events, and without the need to reconcile the incoming data with
    any existing related objects or collections that might not
    be loaded.  The resulting objects from ``load=False`` are always
    produced as "clean", so it is only appropriate that the given objects
    should be "clean" as well, else this suggests a mis-use of the
    method.
:param options: optional sequence of loader options which will be
    applied to the :meth:`_orm.Session.get` method when the merge
    operation loads the existing version of the object from the database.

    .. versionadded:: 1.4.24
