Edit File: session.cpython-311.pyc
� ����u�d���������������������������d�Z�ddlZddlZddlZddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlm Z �dd lm Z �dd lmZ�ddl mZ�ddl mZ�dd l mZ�ddl mZ�ddl mZ�ddl mZ�ddl mZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ �g�d�Z!�ej"����������������������Z# �d��Z$�G�d��de%������������Z&�ej'��������d������������Z(�ej'��������d������������Z)�ej'��������d ������������Z*�ej'��������d!������������Z+�ej'��������d"������������Z,�G�d#��d$e%������������Z-�G�d%��d&e&������������Z.�G�d'��d(e&������������Z/d)��Z0d*��Z1d+��Z2d,��Z3�ej4����������������������Z5dS�)-z1Provides the Session class and related utilities.�����N����)� attributes)�exc)�identity)�loading)�persistence)�query��state)�_class_to_mapper)� _none_set)� _state_mapper)�instance_str)� object_mapper)�object_state)� state_str)�SessionExtension)�UOWTransaction����)�engine)�sql)�util)�inspect)� expression)�Session�SessionTransactionr����sessionmakerc������������������Z�����|�j���������r# �t����������|�j������������������S�#�t����������$�r�Y�nw�xY�wdS�)z\Given an :class:`.InstanceState`, return the :class:`.Session` associated, if any. N)� session_id� _sessions�KeyErrorr ���s��� �M/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/session.py�_state_sessionr#���-���sG������ � ���� ��U�-�.�.���� �� �� ��D� �����4s������ (�(c�������������������������e�Zd�ZdZe�ej��������dd������������d������������������������������Ze�ej��������d������������d������������������������������Z ed����������������Z dS�) �_SessionClassMethodszBClass-level methods for :class:`.Session`, :class:`.sessionmaker`.z1.3z�The :meth:`.Session.close_all` method is deprecated and will be removed in a future release. Please refer to :func:`.session.close_all_sessions`.c������������������"�����t�������������������������dS�)zClose *all* sessions in memory.N)�close_all_sessions)�clss��� r"���� close_allz_SessionClassMethods.close_all=���s������� ����������zsqlalchemy.orm.utilc������������������������|j���������|i�|��S�)zZReturn an identity key. This is an alias of :func:`.util.identity_key`. )�identity_key)r(����orm_util�args�kwargss��� r"���r,���z!_SessionClassMethods.identity_keyI���s�������%�x�$�d�5�f�5�5�5r*���c������������������ �����t����������|������������S�)zxReturn the :class:`.Session` to which an object belongs. This is an alias of :func:`.object_session`. )�object_session)r(����instances��� r"���r1���z#_SessionClassMethods.object_sessionS���s��������h�'�'�'r*���N)�__name__� __module__�__qualname__�__doc__�classmethodr���� deprecatedr)����dependenciesr,���r1�����r*���r"���r%���r%���:���s���������������L�L���T�_� � /������� �����[�� ���T��,�-�-�6��6��.�-���[�6���(��(���[�(��(��(r*���r%����ACTIVE�PREPARED� COMMITTED�DEACTIVE�CLOSEDc��������������������������e�Zd�ZdZdZdd�Zed����������������ZdZ �ed����������������Z � � � �dd�Z ed ����������������Zdd �Zdd�Z dd�Zd ��Zdd�Zd��Zd��Zd��Zd��Zd��Zdd�Zdd�Zd��Zd��ZdS�)r���a���A :class:`.Session`-level transaction. :class:`.SessionTransaction` is a mostly behind-the-scenes object not normally referenced directly by application code. It coordinates among multiple :class:`_engine.Connection` objects, maintaining a database transaction for each one individually, committing or rolling them back all at once. It also provides optional two-phase commit behavior which can augment this coordination operation. The :attr:`.Session.transaction` attribute of :class:`.Session` refers to the current :class:`.SessionTransaction` object in use, if any. The :attr:`.SessionTransaction.parent` attribute refers to the parent :class:`.SessionTransaction` in the stack of :class:`.SessionTransaction` objects. If this attribute is ``None``, then this is the top of the stack. If non-``None``, then this :class:`.SessionTransaction` refers either to a so-called "subtransaction" or a "nested" transaction. A "subtransaction" is a scoping concept that demarcates an inner portion of the outermost "real" transaction. A nested transaction, which is indicated when the :attr:`.SessionTransaction.nested` attribute is also True, indicates that this :class:`.SessionTransaction` corresponds to a SAVEPOINT. **Life Cycle** A :class:`.SessionTransaction` is associated with a :class:`.Session` in its default mode of ``autocommit=False`` immediately, associated with no database connections. As the :class:`.Session` is called upon to emit SQL on behalf of various :class:`_engine.Engine` or :class:`_engine.Connection` objects, a corresponding :class:`_engine.Connection` and associated :class:`.Transaction` is added to a collection within the :class:`.SessionTransaction` object, becoming one of the connection/transaction pairs maintained by the :class:`.SessionTransaction`. The start of a :class:`.SessionTransaction` can be tracked using the :meth:`.SessionEvents.after_transaction_create` event. The lifespan of the :class:`.SessionTransaction` ends when the :meth:`.Session.commit`, :meth:`.Session.rollback` or :meth:`.Session.close` methods are called. At this point, the :class:`.SessionTransaction` removes its association with its parent :class:`.Session`. A :class:`.Session` that is in ``autocommit=False`` mode will create a new :class:`.SessionTransaction` to replace it immediately, whereas a :class:`.Session` that's in ``autocommit=True`` mode will remain without a :class:`.SessionTransaction` until the :meth:`.Session.begin` method is called. The end of a :class:`.SessionTransaction` can be tracked using the :meth:`.SessionEvents.after_transaction_end` event. **Nesting and Subtransactions** Another detail of :class:`.SessionTransaction` behavior is that it is capable of "nesting". This means that the :meth:`.Session.begin` method can be called while an existing :class:`.SessionTransaction` is already present, producing a new :class:`.SessionTransaction` that temporarily replaces the parent :class:`.SessionTransaction`. When a :class:`.SessionTransaction` is produced as nested, it assigns itself to the :attr:`.Session.transaction` attribute, and it additionally will assign the previous :class:`.SessionTransaction` to its :attr:`.Session.parent` attribute. The behavior is effectively a stack, where :attr:`.Session.transaction` refers to the current head of the stack, and the :attr:`.SessionTransaction.parent` attribute allows traversal up the stack until :attr:`.SessionTransaction.parent` is ``None``, indicating the top of the stack. When the scope of :class:`.SessionTransaction` is ended via :meth:`.Session.commit` or :meth:`.Session.rollback`, it restores its parent :class:`.SessionTransaction` back onto the :attr:`.Session.transaction` attribute. The purpose of this stack is to allow nesting of :meth:`.Session.rollback` or :meth:`.Session.commit` calls in context with various flavors of :meth:`.Session.begin`. This nesting behavior applies to when :meth:`.Session.begin_nested` is used to emit a SAVEPOINT transaction, and is also used to produce a so-called "subtransaction" which allows a block of code to use a begin/rollback/commit sequence regardless of whether or not its enclosing code block has begun a transaction. The :meth:`.flush` method, whether called explicitly or via autoflush, is the primary consumer of the "subtransaction" feature, in that it wishes to guarantee that it works within in a transaction block regardless of whether or not the :class:`.Session` is in transactional mode when the method is called. Note that the flush process that occurs within the "autoflush" feature as well as when the :meth:`.Session.flush` method is used **always** creates a :class:`.SessionTransaction` object. This object is normally a subtransaction, unless the :class:`.Session` is in autocommit mode and no transaction exists at all, in which case it's the outermost transaction. Any event-handling logic or other inspection logic needs to take into account whether a :class:`.SessionTransaction` is the outermost transaction, a subtransaction, or a "nested" / SAVEPOINT transaction. .. seealso:: :meth:`.Session.rollback` :meth:`.Session.commit` :meth:`.Session.begin` :meth:`.Session.begin_nested` :attr:`.Session.is_active` :meth:`.SessionEvents.after_transaction_create` :meth:`.SessionEvents.after_transaction_end` :meth:`.SessionEvents.after_commit` :meth:`.SessionEvents.after_rollback` :meth:`.SessionEvents.after_soft_rollback` NFc����������������������||�_���������i�|�_��������||�_��������||�_��������t����������|�_��������|s|rt ����������j��������d�������������|�j���������j��������r|�� �����������������������������������|�j���������j �����������������������������|�j���������|��������������d�S�)NzOCan't start a SAVEPOINT transaction when no existing transaction is in progress)�session�_connections�_parent�nestedr;����_state�sa_exc�InvalidRequestError�_enable_transaction_accounting�_take_snapshot�dispatch�after_transaction_create)�selfrB����parentrE���s��� r"����__init__zSessionTransaction.__init__����s������������������������ �&�� ��,�-����� � ��<�6�� "����!�!�!����6�6�t�|�T�J�J�J�J�Jr*���c�����������������������|�j���������S�)aj��The parent :class:`.SessionTransaction` of this :class:`.SessionTransaction`. If this attribute is ``None``, indicates this :class:`.SessionTransaction` is at the top of the stack, and corresponds to a real "COMMIT"/"ROLLBACK" block. If non-``None``, then this is either a "subtransaction" or a "nested" / SAVEPOINT transaction. If the :attr:`.SessionTransaction.nested` attribute is ``True``, then this is a SAVEPOINT, and if ``False``, indicates this a subtransaction. .. versionadded:: 1.0.16 - use ._parent for previous versions )rD����rM���s��� r"���rN���zSessionTransaction.parent����s������ ��|�r*���c������������������0�����|�j���������d�uo |�j��������t����������u�S��N)rB���rF���r;���rQ���s��� r"���� is_activezSessionTransaction.is_active��s�������|�4�'�A�D�K�6�,A�Ar*����This transaction is closedc����������������������|�j���������t����������u�rt����������j��������d�������������|�j���������t����������u�r|st����������j��������d�������������d�S�|�j���������t ����������u�rE|s=|s=|�j��������rt����������j��������d|�j��������z��d��������������|st����������j��������d�������������d�S�d�S�d�S�|�j���������t����������u�rt����������j��������|�������������d�S�)Nz\This session is in 'committed' state; no further SQL can be emitted within this transaction.z[This session is in 'prepared' state; no further SQL can be emitted within this transaction.z�This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: %s�7s2a)�codez�This session is in 'inactive' state, due to the SQL transaction being rolled back; no further SQL can be emitted within this transaction.) rF���r=���rG���rH���r<���r>����_rollback_exceptionr?����ResourceClosedError)rM����prepared_ok�rollback_ok�deactive_ok� closed_msgs��� r"����_assert_activez!SessionTransaction._assert_active��s,�������;�)�#�#��,�>����� ���[�H� $� $��� ��0�B������ �� � ��[�H� $� $��� �{�� ��+��� �4�6� ��2�3��$���������%��� �4�F������ �� �� �� ������[�F� "� "��,�Z�8�8�8��#� "r*���c������������������ �����|�j���������p|�j���������S�rS���)rE���rD���rQ���s��� r"����_is_transaction_boundaryz+SessionTransaction._is_transaction_boundary3��s�������{�.�$�,�.�.r*���c������������������|�����|���������������������������������������|�j��������j��������|fi�|��}|����������������������||������������S�rS���)r_���rB����get_bind�_connection_for_bind)rM����bindkey�execution_optionsr/����binds��� r"���� connectionzSessionTransaction.connection7��sG������������$�t�|�$�W�7�7��7�7���(�(��/@�A�A�Ar*���c������������������X�����|��������������������������������������t����������|�j��������|�|�������������S�)N�rE���)r_���r���rB���)rM���rE���s��� r"����_beginzSessionTransaction._begin<��s+������������!�$�,��V�D�D�D�Dr*���c�����������������������|�}d}|r7||fz ��}|j���������|u�rn'|j����������t����������j��������d|z���������������|j���������}|�7|S�)Nr:���z4Transaction %s is not on the active transaction list)rD���rG���rH���)rM����upto�current�results��� r"����_iterate_self_and_parentsz,SessionTransaction._iterate_self_and_parents@��sr������������ *��w�j� �F���$�&�&����(��0�J�������� �"�/����� *��� r*���c����������������������|�j���������sF|�j��������j��������|�_��������|�j��������j��������|�_��������|�j��������j��������|�_��������|�j��������j��������|�_��������d�S�|�j��������j��������s|�j��������������������������������������������t����������j ����������������������|�_��������t����������j ����������������������|�_��������t����������j ����������������������|�_��������t����������j ����������������������|�_��������d�S�rS���)ra���rD����_new�_deleted�_dirty� _key_switchesrB���� _flushing�flush�weakref�WeakKeyDictionaryrQ���s��� r"���rJ���z!SessionTransaction._take_snapshotR��s��������,�� ���)�D�I� �L�1�D�M��,�-�D�K�!%��!;�D���F��|�%�� !��L��� � � ��-�/�/�� ��1�3�3�� ��/�1�1���$�6�8�8����r*���c����������������������|�j���������sJ��t����������|�j�����������������������������������������|�j��������j��������������������}|�j�����������������������������|d��������������|�j�������������������������������������������D�]Q\��}\��}}|�j��������j��������� ��������������������|�������������||_ ��������||vr|�j��������j�����������������������������|��������������Rt����������|�j�����������������������������������������|�j��������j��������������������D�]}|�j��������� ��������������������|d���������������|�j��������j��������rJ��|�j��������j�������������������������������������������D�]>}|r|j��������s ||�j��������v�r*|���������������������|j��������|�j��������j��������j����������������������?dS�)zmRestore the restoration state taken before a transaction began. Corresponds to a rollback. T��to_transient)�revert_deletionN)ra����setrr����unionrB����_expunge_statesru����items�identity_map�safe_discard�key�replacers����_update_impl� all_states�modifiedrt����_expire�dict� _modified)rM���� dirty_only� to_expunge�s�oldkey�newkeys��� r"����_restore_snapshotz$SessionTransaction._restore_snapshotb��s��������,�,�,�,����^�^�)�)�$�,�*;�<�<� ���$�$�Z�d�$�C�C�C�#'�#5�#;�#;�#=�#=�� 5�� 5��A����� �L�%�2�2�1�5�5�5���A�E��� �"�"���)�1�1�!�4�4�4���T�]�#�#�)�)�$�,�*?�@�@�� ?�� ?�A��L�%�%�a��%�>�>�>�>��<�(�(�(�(���*�5�5�7�7�� G�� G�A��� G���� G�q�D�K�/?�/?�� � �!�&�$�,�";�"E�F�F�F�� G�� Gr*���c����������������������|�j���������sJ��|�j��������s�|�j��������j��������r�|�j��������j�������������������������������������������D�],}|���������������������|j��������|�j��������j��������j����������������������-t����������j �����������������������������t����������|�j ��������������������|�j���������������������|�j ��������������������������������������������dS�|�j��������r�|�j��������j�����������������������������|�j���������������������|�j��������j�����������������������������|�j���������������������|�j��������j �����������������������������|�j ���������������������|�j��������j�����������������������������|�j���������������������dS�dS�)zjRemove the restoration state taken before a transaction began. Corresponds to a commit. N)ra���rE���rB����expire_on_commitr����r����r����r����r�����statelib� InstanceState�_detach_states�listrs����clearrD���rr����updatert���ru���)rM���r����s��� r"����_remove_snapshotz#SessionTransaction._remove_snapshot���s@�������,�,�,�,��{�� B�t�|�<�� B��\�.�9�9�;�;�� G�� G��� � �!�&�$�,�";�"E�F�F�F�F��"�1�1��T�]�#�#�T�\� �� �� �� �M���!�!�!�!�!� �[�� B��L��$�$�T�Y�/�/�/��L��&�&�t�{�3�3�3��L�!�(�(���7�7�7��L�&�-�-�d�.@�A�A�A�A�A� B�� Br*���c������������������(����|��������������������������������������||�j��������v�r)|rt����������j��������d�������������|�j��������|���������d���������S�d}|�j��������r%|�j�����������������������������||������������}|�j��������s|S�nUt����������|t����������j ��������������������r%|}|j��������|�j��������v�rt����������j��������d�������������n|�����������������������������������}d} �|r �|j ��������di�|��}|�j��������j��������r|�j���������|�����������������������������������}n0|�j��������r|�����������������������������������}n|�����������������������������������}||||ufx|�j��������|<���|�j��������|j��������<���|�j��������j�����������������������������|�j��������|�|�������������|S�#��|r|��������������������������������������xY�w)NzOConnection is already established for the given bind; execution_options ignoredr���FzMSession already has a Connection associated for the given Connection's EngineTr:���)r_���rC���r����warnrD���rd���rE���� isinstancer���� ConnectionrG���rH����_contextual_connectrf���rB����twophase�begin_twophase�begin_nested�beginrK����after_begin�close)rM���rg���rf���� local_connect�conn�transactions��� r"���rd���z'SessionTransaction._connection_for_bind���s�������������4�$�$�$� �� �� �<��������$�T�*�1�-�-�� ��<�� %��<�4�4�T�;L�M�M�D��;�� ��� ���$�� 1�2�2�� %����;�$�"3�3�3� �4�4�������4���/�/�1�1�� $� � � �� C�-�t�-�B�B�0A�B�B���|�$�� +���)=�"�1�1�3�3������ +�"�/�/�1�1���"�j�j�l�l������D� �H�� �D��d�#�d�&7���&D� � �L�!�-�-�d�l�D�$�G�G�G��K�� ���� �� � �������s ����A'E8��8Fc������������������|�����|�j����������|�j��������j��������st����������j��������d�������������|�������������������������������������d�S�)NzD'twophase' mode not enabled, or not root transaction; can't prepare.)rD���rB���r����rG���rH���� _prepare_implrQ���s��� r"����preparezSessionTransaction.prepare���sH�������<�#�4�<�+@�#��,�!����� �� �������r*���c������������������,����|��������������������������������������|�j���������|�j��������r$|�j��������j�����������������������������|�j���������������������|�j��������j��������}||�ur-|���������������������|��������������D�]}|�������������������������������������|�j��������j ��������sZt����������d������������D�]6}|�j�������������������������������������������r�n.|�j���������������������������������������������7t����������j��������d�������������|�j����������|�j��������j��������r� �t!����������|�j�������������������������������������������������������D�]}|d����������������������������������������������nF#��t)����������j����������������������5��|�������������������������������������d�d�d��������������n#�1�swxY�w�Y���Y�nxY�wt.����������|�_��������d�S�)N�rm����d���zrOver 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects?r���)r_���rD���rE���rB���rK���� before_commitr����rp����commitrv����range� _is_cleanrw���r���� FlushErrorr����r~���rC����valuesr����r����safe_reraise�rollbackr<���rF���)rM����stx�subtransaction�_flush_guard�ts��� r"���r����z SessionTransaction._prepare_impl���s�������������<��4�;���L�!�/�/���=�=�=��l�&���d�?�?�"%�"?�"?�T�"?�"J�"J�� (�� (���%�%�'�'�'�'��|�%�� � %�c� � �� �� ���<�)�)�+�+����E���"�"�$�$�$�$��n�,��������<��D�L�$9�� $��T�.�5�5�7�7�8�8��#��#�A��a�D�L�L�N�N�N�N�#�� $��&�(�(��$��$��M�M�O�O�O�$��$��$��$��$��$��$��$��$��$��$�����$��$��$��$�����������s1����>AE��F�E8�,F�8E< �<F�?E< ��Fc�����������������������|�����������������������d��������������|�j��������t����������ur|�������������������������������������|�j���������|�j��������r�t ����������|�j�������������������������������������������������������D�]}|d���������� ������������������������������������t����������|�_��������|�j��������j��������� ��������������������|�j���������������������|�j��������j��������r|�������������������������������������|�������������������������������������|�j��������S�)NT)r[���r���)r_���rF���r<���r����rD���rE���r~���rC���r����r����r=���rB���rK����after_commitrI���r����r����)rM���r����s��� r"���r����zSessionTransaction.commit���s������������-�-�-��;�h�&�&���� � � ��<��4�;����*�1�1�3�3�4�4�� �� ���!���� � � � �#�D�K��L�!�.�.�t�|�<�<�<��|�:�� (��%�%�'�'�'�� � �����|�r*���c����������������������|�����������������������dd��������������|�j��������j��������}||�ur-|���������������������|��������������D�]}|�������������������������������������|�}d�}|�j��������t����������t����������fv��r4|������������������������������������D��]}|j���������|j ���������r� �t����������|j�������������������������������������������������������D�]}|d���������� ������������������������������������t����������|_��������|�j��������j�����������������������������|�j���������������������n#��t#����������j����������������������}Y�nxY�wt����������|_��������|�j��������j��������r|���������������������|j ����������������������n9#�t����������|_��������|�j��������j��������r|���������������������|j ����������������������w�w�xY�w|}�nt����������|_���������� |�j��������}|sJ|j��������rC|�����������������������������������s/t-����������j��������d�������������|���������������������|j ����������������������|�������������������������������������|�j��������r%|r#t#����������j����������������������d���������|�j��������_��������|r"t-����������j��������|d���������|d�����������������������|j�����������������������������||��������������|�j��������S�) NT)r[���r\���r����r���)r����z\Session's state has been changed on a non-active transaction - this state will be discarded.r�����with_traceback)r_���rB���r����rp���r����rF���r;���r<���rD���rE���r~���rC���r����r����r>���rK����after_rollback�sys�exc_inforI���r����r����r���r����rY����raise_�after_soft_rollback) rM����_capture_exceptionr����r�����boundary�rollback_errr����r�����sesss ��� r"���r����zSessionTransaction.rollback��s����������$��?�?�?��l�&���d�?�?�"%�"?�"?�T�"?�"J�"J�� '�� '���$�$�&�&�&�&������;�6�8�,�,�,�#�=�=�?�?�� 2�� 2���&�.�+�2D�.� �!$�[�%=�%D�%D�%F�%F�!G�!G��,��,�A��a�D�M�M�O�O�O�O�-5��*���-�<�<�T�\�J�J�J�J��6�'*�|�~�~�������-5��*��<�F���'�9�9�+6�+=��:����������.6��*��<�F���'�9�9�+6�+=��:�������������� +�H��E�)1�K�&�&��|���� C��3� C���N�N�$�$� C�� �I�%� �� �� � � �&�&�(�/�&�B�B�B�� � �����<�� A�.�� A�/2�|�~�~�a�/@�D�L�,��� I��K��Q���Q��H�H�H�H�� �)�)�$��5�5�5��|�s����A3D � E� D!�E�6Fc�����������������������|�j���������|�j��������_��������|�j����������nt����������|�j�������������������������������������������������������D�]G\��}}}|r|������������������������������������|r|�������������������������������������3|�������������������������������������Ht����������|�_ ��������|�j��������j �����������������������������|�j��������|��������������|�j����������%|�j��������j��������s|�j��������� �����������������������������������d�|�_��������d�|�_��������d�S�rS���)rD���rB���r����r~���rC���r����� invalidater����r?���rF���rK����after_transaction_end� autocommitr����)rM���r����rh���r����� autocloses��� r"���r����zSessionTransaction.closeD��s�������#'�<��� ��<��69��!�(�(�*�*�7��7�� (�� (�2� �K�����,��)�)�+�+�+���(��$�$�&�&�&�&��%�%�'�'�'�'�������3�3�D�L�$�G�G�G��<���<�*�� %���"�"�$�$�$���� ����r*���c�����������������������|�S�rS���r:���rQ���s��� r"���� __enter__zSessionTransaction.__enter__Z��s�������r*���c������������������>����|�����������������������dd��������������|�j��������j���������d�S�|�a �|�������������������������������������d�S�#��t ����������j����������������������5��|�������������������������������������d�d�d��������������n#�1�swxY�w�Y���Y�d�S�Y�d�S�xY�w|�������������������������������������d�S�)NT)r]���r[���)r_���rB���r����r����r���r����r����)rM����type_�value� tracebacks��� r"����__exit__zSessionTransaction.__exit__]��s�����������$��?�?�?��<�#�+��F��=� $���� � � � � �� $��&�(�(��$��$��M�M�O�O�O�$��$��$��$��$��$��$��$��$��$��$�����$��$��$��$��$��$��$��$��$��$����� �M�M�O�O�O�O�Os-����?��B�A5�)B�5A9 �9B�<A9 �=B)NF)FFFrU���rS����F)r3���r4���r5���r6���rY���rO����propertyrN���rE���rT���r_���ra���rh���rk���rp���rJ���r����r����rd���r����r����r����r����r����r����r����r:���r*���r"���r���r���e���s��������������s��s�j���K��K��K��K�"�������X��"��F����B��B���X�B� ����/�%9��%9��%9��%9�N��/��/���X�/�B��B��B��B� E��E��E��E��������$9��9��9� G��G��G��G�@B��B��B�,3��3��3�j����������@�����$;��;��;��;�z!��!��!��!�,�������������r*���r���c��������������������$����e�Zd�ZdZdZ�ej��������ddd������������� � � � � � � � � � � � �dNd ���������������ZdZdZ �ej ��������d����������������ZdOd�Zd ��Z d��Zd��Zd��Z � � � � �dPd�ZdQd�ZdRd�ZdRd�Zd��Zd��Zd��Zd��Zd��Zd��Zd��ZdSd�Zd��Zeej��������d������������������������������Z d��Z! � � �dRd �Z"d!��Z#dQd"�Z$d#��Z%d$��Z&�ej'��������d%d&������������d'����������������Z(d(��Z)dTd)�Z*d*��Z+d+��Z,d,��Z-dUd-�Z.d.��Z/d/��Z0d0��Z1d1��Z2dUd2�Z3 � � �dVd3�Z4d4��Z5d5��Z6dTd6�Z7d7��Z8d8��Z9d9��Z:d:��Z;d;��Z<d<��Z=d=��Z>dQd>�Z?d?��Z@d@��ZAdQdA�ZB � � �dWdB�ZC �dOdC�ZDdD��ZEdE��ZF�ej��������dF�G������������dXdH���������������ZGedI����������������ZHdZI �edJ����������������ZJedK����������������ZKedL����������������ZLedM����������������ZMdS�)Yr���z�Manages persistence operations for ORM-mapped objects. The Session's usage paradigm is described at :doc:`/orm/session`. )�__contains__�__iter__�add�add_allr����r����r����r����rh����delete�execute�expire� expire_all�expunge�expunge_allrw���rc����is_modified�bulk_save_objects�bulk_insert_mappings�bulk_update_mappings�merger ����refreshr�����scalar)z1.0a���The :paramref:`.Session.weak_identity_map` parameter as well as the strong-referencing identity map are deprecated, and will be removed in a future release. For the use case where objects present in a :class:`.Session` need to be automatically strong referenced, see the recipe at :ref:`session_referencing_behavior` for an event-based approach to maintaining strong identity references. )�0.7zxThe :paramref:`.Session._enable_transaction_accounting` parameter is deprecated and will be removed in a future release.)r����z�:class:`.SessionExtension` is deprecated in favor of the :class:`.SessionEvents` listener interface. The :paramref:`.Session.extension` parameter will be removed in a future release.)�weak_identity_maprI���� extensionNTFc �����������������������|dv�rt�����������j��������|�_��������nt�����������j��������|�_��������|������������������������������������|�_��������i�|�_��������i�|�_��������||�_��������i�|�_��������d|�_ ��������d|�_ ��������d|�_��������t������������������������|�_ ��������||�_��������||�_��������||�_��������| |�_��������||�_��������||�_��������|r|nt(����������j��������|�_��������|r|�j�����������������������������|�������������| r,t3����������j��������| ������������D�]} t7����������j��������|�| ��������������|�0|�����������������������������������D�]\��}}|����������������������||��������������|�j��������s|�������������������������������������|�t@����������|�j ��������<���dS�)a���Construct a new Session. See also the :class:`.sessionmaker` function which is used to generate a :class:`.Session`-producing callable with a given set of arguments. :param autocommit: .. warning:: The autocommit flag is **not for general use**, and if it is used, queries should only be invoked within the span of a :meth:`.Session.begin` / :meth:`.Session.commit` pair. Executing queries outside of a demarcated transaction is a legacy mode of usage, and can in some cases lead to concurrent connection checkouts. Defaults to ``False``. When ``True``, the :class:`.Session` does not keep a persistent transaction running, and will acquire connections from the engine on an as-needed basis, returning them immediately after their use. Flushes will begin and commit (or possibly rollback) their own transaction if no transaction is present. When using this mode, the :meth:`.Session.begin` method is used to explicitly start transactions. .. seealso:: :ref:`session_autocommit` :param autoflush: When ``True``, all query operations will issue a :meth:`~.Session.flush` call to this ``Session`` before proceeding. This is a convenience feature so that :meth:`~.Session.flush` need not be called repeatedly in order for database queries to retrieve results. It's typical that ``autoflush`` is used in conjunction with ``autocommit=False``. In this scenario, explicit calls to :meth:`~.Session.flush` are rarely needed; you usually only need to call :meth:`~.Session.commit` (which flushes) to finalize changes. :param bind: An optional :class:`_engine.Engine` or :class:`_engine.Connection` to which this ``Session`` should be bound. When specified, all SQL operations performed by this session will execute via this connectable. :param binds: A dictionary which may specify any number of :class:`_engine.Engine` or :class:`_engine.Connection` objects as the source of connectivity for SQL operations on a per-entity basis. The keys of the dictionary consist of any series of mapped classes, arbitrary Python classes that are bases for mapped classes, :class:`_schema.Table` objects and :class:`_orm.Mapper` objects. The values of the dictionary are then instances of :class:`_engine.Engine` or less commonly :class:`_engine.Connection` objects. Operations which proceed relative to a particular mapped class will consult this dictionary for the closest matching entity in order to determine which :class:`_engine.Engine` should be used for a particular SQL operation. The complete heuristics for resolution are described at :meth:`.Session.get_bind`. Usage looks like:: Session = sessionmaker(binds={ SomeMappedClass: create_engine('postgresql://engine1'), SomeDeclarativeBase: create_engine('postgresql://engine2'), some_mapper: create_engine('postgresql://engine3'), some_table: create_engine('postgresql://engine4'), }) .. seealso:: :ref:`session_partitioning` :meth:`.Session.bind_mapper` :meth:`.Session.bind_table` :meth:`.Session.get_bind` :param \class_: Specify an alternate class other than ``sqlalchemy.orm.session.Session`` which should be used by the returned class. This is the only argument that is local to the :class:`.sessionmaker` function, and is not sent directly to the constructor for ``Session``. :param enable_baked_queries: defaults to ``True``. A flag consumed by the :mod:`sqlalchemy.ext.baked` extension to determine if "baked queries" should be cached, as is the normal operation of this extension. When set to ``False``, all caching is disabled, including baked queries defined by the calling application as well as those used internally. Setting this flag to ``False`` can significantly reduce memory use, however will also degrade performance for those areas that make use of baked queries (such as relationship loaders). Additionally, baked query logic in the calling application or potentially within the ORM that may be malfunctioning due to cache key collisions or similar can be flagged by observing if this flag resolves the issue. .. versionadded:: 1.2 :param _enable_transaction_accounting: A legacy-only flag which when ``False`` disables *all* 0.5-style object accounting on transaction boundaries. :param expire_on_commit: Defaults to ``True``. When ``True``, all instances will be fully expired after each :meth:`~.commit`, so that all attribute/object access subsequent to a completed transaction will load from the most recent database state. .. seealso:: :ref:`session_committing` :param extension: An optional :class:`~.SessionExtension` instance, or a list of such instances, which will receive pre- and post- commit and flush events, as well as a post-rollback event. :param info: optional dictionary of arbitrary data to be associated with this :class:`.Session`. Is available via the :attr:`.Session.info` attribute. Note the dictionary is copied at construction time so that modifications to the per- :class:`.Session` dictionary will be local to that :class:`.Session`. .. versionadded:: 0.9.0 :param query_cls: Class which should be used to create new Query objects, as returned by the :meth:`~.Session.query` method. Defaults to :class:`_query.Query`. :param twophase: When ``True``, all transactions will be started as a "two phase" transaction, i.e. using the "two phase" semantics of the database in use along with an XID. During a :meth:`~.commit`, after :meth:`~.flush` has been issued for all attached databases, the :meth:`~.TwoPhaseTransaction.prepare` method on each database's :class:`.TwoPhaseTransaction` will be called. This allows each database to roll back the entire transaction, before each transaction is committed. :param weak_identity_map: Defaults to ``True`` - when set to ``False``, objects placed in the :class:`.Session` will be strongly referenced until explicitly removed or the :class:`.Session` is closed. �TNFN)!r����WeakInstanceDict� _identity_cls�StrongInstanceDictr����rr���rs���rg����_Session__bindsrv����_warn_on_eventsr�����_new_sessionid�hash_key� autoflushr����r�����enable_baked_queriesrI���r����r ����Query� _query_cls�infor����r����to_listr����_adapt_listenerr����� _add_bindr����r ���)rM���rg���r����r����rI���r����r����r�����bindsr����r����r����� query_cls�extr����s��� r"���rO���zSession.__init__���sr�����z���,�,�!)�!:�D���!)�!<�D�� �.�.�0�0����� ��� ��� �������$������&�(�(�� �"���$��� 0���$8��!�.L��+� �� �'0�A�)�)�e�k����� #��I���T�"�"�"��� <��|�I�.�.�� <�� <�� �0��s�;�;�;�;���"�[�[�]�]�� *�� *� ��T����s�D�)�)�)�)���� ��J�J�L�L�L�#'� �$�-� � � r*���c�����������������������i�S�)a���A user-modifiable dictionary. The initial value of this dictionary can be populated using the ``info`` argument to the :class:`.Session` constructor or :class:`.sessionmaker` constructor or factory methods. The dictionary here is always local to this :class:`.Session` and can be modified independently of all other :class:`.Session` objects. .. versionadded:: 0.9.0 r:���rQ���s��� r"���r����zSession.infox��s �������� r*���c�����������������������|�j����������9|s|r!|�j������������������������������|�������������|�_���������n*t����������j��������d�������������t ����������|�|�������������|�_���������|�j���������S�)a8 ��Begin a transaction on this :class:`.Session`. .. warning:: The :meth:`.Session.begin` method is part of a larger pattern of use with the :class:`.Session` known as **autocommit mode**. This is essentially a **legacy mode of use** and is not necessary for new applications. The :class:`.Session` normally handles the work of "begin" transparently, which in turn relies upon the Python DBAPI to transparently "begin" transactions; there is **no need to explicitly begin transactions** when using modern :class:`.Session` programming patterns. In its default mode of ``autocommit=False``, the :class:`.Session` does all of its work within the context of a transaction, so as soon as you call :meth:`.Session.commit`, the next transaction is implicitly started when the next database operation is invoked. See :ref:`session_autocommit` for further background. The method will raise an error if this :class:`.Session` is already inside of a transaction, unless :paramref:`~.Session.begin.subtransactions` or :paramref:`~.Session.begin.nested` are specified. A "subtransaction" is essentially a code embedding pattern that does not affect the transactional state of the database connection unless a rollback is emitted, in which case the whole transaction is rolled back. For documentation on subtransactions, please see :ref:`session_subtransactions`. :param subtransactions: if True, indicates that this :meth:`~.Session.begin` can create a "subtransaction". :param nested: if True, begins a SAVEPOINT transaction and is equivalent to calling :meth:`~.Session.begin_nested`. For documentation on SAVEPOINT transactions, please see :ref:`session_begin_nested`. :return: the :class:`.SessionTransaction` object. Note that :class:`.SessionTransaction` acts as a Python context manager, allowing :meth:`.Session.begin` to be used in a "with" block. See :ref:`session_autocommit` for an example. .. seealso:: :ref:`session_autocommit` :meth:`.Session.begin_nested` Nrj���zSA transaction is already begun. Use subtransactions=True to allow subtransactions.)r����rk���rG���rH���r���)rM����subtransactionsrE���s��� r"���r����z Session.begin���sw������h���'��� �&�� �#'�#3�#:�#:�&�#:�#I�#I�� � ��0�E������ � 2�$�v�F�F�F�D����r*���c������������������.�����|�����������������������d�������������S�)a"��Begin a "nested" transaction on this Session, e.g. SAVEPOINT. The target database(s) and associated drivers must support SQL SAVEPOINT for this method to function correctly. For documentation on SAVEPOINT transactions, please see :ref:`session_begin_nested`. :return: the :class:`.SessionTransaction` object. Note that :class:`.SessionTransaction` acts as a context manager, allowing :meth:`.Session.begin_nested` to be used in a "with" block. See :ref:`session_begin_nested` for a usage example. .. seealso:: :ref:`session_begin_nested` :ref:`pysqlite_serializable` - special workarounds required with the SQLite driver in order for SAVEPOINT to work correctly. Trj���)r����rQ���s��� r"���r����zSession.begin_nested���s������.��z�z��z�&�&�&r*���c������������������J�����|�j����������dS�|�j���������������������������������������������dS�)a���Rollback the current transaction in progress. If no transaction is in progress, this method is a pass-through. This method rolls back the current transaction or nested transaction regardless of subtransactions being in effect. All subtransactions up to the first real transaction are closed. Subtransactions occur when :meth:`.begin` is called multiple times. .. seealso:: :ref:`session_rollback` N)r����r����rQ���s��� r"���r����zSession.rollback���s-���������#��D���%�%�'�'�'�'�'r*���c�����������������������|�j����������0|�j��������s|�������������������������������������nt����������j��������d�������������|�j���������������������������������������������dS�)a���Flush pending changes and commit the current transaction. If no transaction is in progress, this method raises an :exc:`~sqlalchemy.exc.InvalidRequestError`. By default, the :class:`.Session` also expires all database loaded state on all ORM-managed attributes after transaction commit. This so that subsequent operations load the most recent data from the database. This behavior can be disabled using the ``expire_on_commit=False`` option to :class:`.sessionmaker` or the :class:`.Session` constructor. If a subtransaction is in effect (which occurs when begin() is called multiple times), the subtransaction will be closed, and the next call to ``commit()`` will operate on the enclosing transaction. When using the :class:`.Session` in its default mode of ``autocommit=False``, a new transaction will be begun immediately after the commit, but note that the newly begun transaction does *not* use any connection resources until the first SQL is actually emitted. .. seealso:: :ref:`session_committing` N�No transaction is begun.)r����r����r����rG���rH���r����rQ���s��� r"���r����zSession.commit���sT������8���#��?�� M�� � ������0�1K�L�L�L�����!�!�!�!�!r*���c�����������������������|�j����������0|�j��������s|�������������������������������������nt����������j��������d�������������|�j���������������������������������������������dS�)ax��Prepare the current transaction in progress for two phase commit. If no transaction is in progress, this method raises an :exc:`~sqlalchemy.exc.InvalidRequestError`. Only root transactions of two phase sessions can be prepared. If the current transaction is not such, an :exc:`~sqlalchemy.exc.InvalidRequestError` is raised. Nr��)r����r����r����rG���rH���r����rQ���s��� r"���r����zSession.prepare��sT���������#��?�� M�� � ������0�1K�L�L�L��� � �"�"�"�"�"r*���c������������������V�����|��|�j���������|fd|i|��}|����������������������|||�������������S�)a� ��Return a :class:`_engine.Connection` object corresponding to this :class:`.Session` object's transactional state. If this :class:`.Session` is configured with ``autocommit=False``, either the :class:`_engine.Connection` corresponding to the current transaction is returned, or if no transaction is in progress, a new one is begun and the :class:`_engine.Connection` returned (note that no transactional state is established with the DBAPI until the first SQL statement is emitted). Alternatively, if this :class:`.Session` is configured with ``autocommit=True``, an ad-hoc :class:`_engine.Connection` is returned using :meth:`_engine.Engine.connect` on the underlying :class:`_engine.Engine`. Ambiguity in multi-bind or unbound :class:`.Session` objects can be resolved through any of the optional keyword arguments. This ultimately makes usage of the :meth:`.get_bind` method for resolution. :param bind: Optional :class:`_engine.Engine` to be used as the bind. If this engine is already involved in an ongoing transaction, that connection will be used. This argument takes precedence over ``mapper``, ``clause``. :param mapper: Optional :func:`.mapper` mapped class, used to identify the appropriate bind. This argument takes precedence over ``clause``. :param clause: A :class:`_expression.ClauseElement` (i.e. :func:`_expression.select`, :func:`_expression.text`, etc.) which will be used to locate a bind, if a bind cannot otherwise be identified. :param close_with_result: Passed to :meth:`_engine.Engine.connect`, indicating the :class:`_engine.Connection` should be considered "single use", automatically closing when the first result set is closed. This flag only has an effect if this :class:`.Session` is configured with ``autocommit=True`` and does not already have a transaction in progress. :param execution_options: a dictionary of execution options that will be passed to :meth:`_engine.Connection.execution_options`, **when the connection is first procured only**. If the connection is already present within the :class:`.Session`, a warning is emitted and the arguments are ignored. .. versionadded:: 0.9.9 .. seealso:: :ref:`session_transaction_isolation` :param \**kw: Additional keyword arguments are sent to :meth:`get_bind`, allowing additional arguments to be passed to custom implementations of :meth:`get_bind`. N�clause)�close_with_resultrf���)rc���rd���)rM����mapperr ��rg���r ��rf����kws��� r"���rh���zSession.connection+��sN������P��<� �4�=��=�=��=�"�=�=�D��(�(��/�/��)�� �� �� r*���c�����������������������|�j����������|�j������������������������������||������������S��|j��������di�|��}|r �|j��������di�|��}|S�)Nr:���)r����rd���r����rf���)rM���r���rf���r��r����s��� r"���rd���zSession._connection_for_bind|��sm��������'��#�8�8��)����� ��.�6�-�3�3��3�3�D� �� C�-�t�-�B�B�0A�B�B���Kr*���c�����������������������t����������j��������|d�������������}|��|�j��������|fd|i|��}|����������������������|d����������������������������������||pi�������������S�)a���Execute a SQL expression construct or string statement within the current transaction. Returns a :class:`_engine.ResultProxy` representing results of the statement execution, in the same manner as that of an :class:`_engine.Engine` or :class:`_engine.Connection`. E.g.:: result = session.execute( user_table.select().where(user_table.c.id == 5) ) :meth:`~.Session.execute` accepts any executable clause construct, such as :func:`_expression.select`, :func:`_expression.insert`, :func:`_expression.update`, :func:`_expression.delete`, and :func:`_expression.text`. Plain SQL strings can be passed as well, which in the case of :meth:`.Session.execute` only will be interpreted the same as if it were passed via a :func:`_expression.text` construct. That is, the following usage:: result = session.execute( "SELECT * FROM user WHERE id=:param", {"param":5} ) is equivalent to:: from sqlalchemy import text result = session.execute( text("SELECT * FROM user WHERE id=:param"), {"param":5} ) The second positional argument to :meth:`.Session.execute` is an optional parameter set. Similar to that of :meth:`_engine.Connection.execute`, whether this is passed as a single dictionary, or a sequence of dictionaries, determines whether the DBAPI cursor's ``execute()`` or ``executemany()`` is used to execute the statement. An INSERT construct may be invoked for a single row:: result = session.execute( users.insert(), {"id": 7, "name": "somename"}) or for multiple rows:: result = session.execute(users.insert(), [ {"id": 7, "name": "somename7"}, {"id": 8, "name": "somename8"}, {"id": 9, "name": "somename9"} ]) The statement is executed within the current transactional context of this :class:`.Session`. The :class:`_engine.Connection` which is used to execute the statement can also be acquired directly by calling the :meth:`.Session.connection` method. Both methods use a rule-based resolution scheme in order to determine the :class:`_engine.Connection`, which in the average case is derived directly from the "bind" of the :class:`.Session` itself, and in other cases can be based on the :func:`.mapper` and :class:`_schema.Table` objects passed to the method; see the documentation for :meth:`.Session.get_bind` for a full description of this scheme. The :meth:`.Session.execute` method does *not* invoke autoflush. The :class:`_engine.ResultProxy` returned by the :meth:`.Session.execute` method is returned with the "close_with_result" flag set to true; the significance of this flag is that if this :class:`.Session` is autocommitting and does not have a transaction-dedicated :class:`_engine.Connection` available, a temporary :class:`_engine.Connection` is established for the statement execution, which is closed (meaning, returned to the connection pool) when the :class:`_engine.ResultProxy` has consumed all available data. This applies *only* when the :class:`.Session` is configured with autocommit=True and no transaction has been started. :param clause: An executable statement (i.e. an :class:`.Executable` expression such as :func:`_expression.select`) or string SQL statement to be executed. :param params: Optional dictionary, or list of dictionaries, containing bound parameter values. If a single dictionary, single-row execution occurs; if a list of dictionaries, an "executemany" will be invoked. The keys in each dictionary must correspond to parameter names present in the statement. :param mapper: Optional :func:`.mapper` or mapped class, used to identify the appropriate bind. This argument takes precedence over ``clause`` when locating a bind. See :meth:`.Session.get_bind` for more details. :param bind: Optional :class:`_engine.Engine` to be used as the bind. If this engine is already involved in an ongoing transaction, that connection will be used. This argument takes precedence over ``mapper`` and ``clause`` when locating a bind. :param \**kw: Additional keyword arguments are sent to :meth:`.Session.get_bind()` to allow extensibility of "bind" schemes. .. seealso:: :ref:`sqlexpression_toplevel` - Tutorial on using Core SQL constructs. :ref:`connections_toplevel` - Further information on direct statement execution. :meth:`_engine.Connection.execute` - core level statement execution method, which is :meth:`.Session.execute` ultimately uses in order to execute the statement. T)�allow_coercion_to_textNr ��)r ��)r����_literal_as_textrc���rd���r�����rM���r ���paramsr��rg���r��s��� r"���r����zSession.execute���sz������B��,��4� �� �� ����<� �4�=��=�=��=�"�=�=�D��(�(���(�F�F�N�N��F�L�b� �� �� r*���c������������������J������|�j���������|f|||d�|�������������������������������������S�)z:Like :meth:`~.Session.execute` but return a scalar result.)r��r��rg���)r����r����r��s��� r"���r����zSession.scalar��s?��������t�|�� �!�&�t� �� �?A� �� � �&�(�(� r*���c������������������2�����|�����������������������d��������������dS�)a>��Close this Session. This clears all items and ends any transaction in progress. If this session were created with ``autocommit=False``, a new transaction is immediately begun. Note that this new transaction does not use any connection resources until they are first needed. F�r����N��_close_implrQ���s��� r"���r����z Session.close��s!������� ���E��*�*�*�*�*r*���c������������������2�����|�����������������������d��������������dS�)a��Close this Session, using connection invalidation. This is a variant of :meth:`.Session.close` that will additionally ensure that the :meth:`_engine.Connection.invalidate` method will be called on all :class:`_engine.Connection` objects. This can be called when the database is known to be in a state where the connections are no longer safe to be used. E.g.:: try: sess = Session() sess.add(User()) sess.commit() except gevent.Timeout: sess.invalidate() raise except: sess.rollback() raise This clears all items and ends any transaction in progress. If this session were created with ``autocommit=False``, a new transaction is immediately begun. Note that this new transaction does not use any connection resources until they are first needed. .. versionadded:: 0.9.9 Tr��Nr��rQ���s��� r"���r����zSession.invalidate&��s"������@� ���D��)�)�)�)�)r*���c�����������������������|��������������������������������������|�j���������1|�j�������������������������������������������D�]}|���������������������|��������������d�S�d�S�rS���)r����r����rp���r����)rM���r����r����s��� r"���r��zSession._close_implH��sd��������������'�#�/�I�I�K�K�� .�� .���!�!�*�-�-�-�-��(�'� .�� .r*���c������������������������|�j��������������������������������������������t����������|�j��������������������z���}|������������������������������������|�_���������i�|�_��������i�|�_��������t����������j�����������������������������||��������������dS�)z�Remove all object instances from this ``Session``. This is equivalent to calling ``expunge(obj)`` on all objects in this ``Session``. N) r����r����r����rr���r����rs���r����r����r����)rM���r����s��� r"���r����zSession.expunge_allN��sf��������&�1�1�3�3�d�4�9�o�o�E� � �.�.�0�0����� ��� ���-�-�j�$�?�?�?�?�?r*���c���������������������� �t����������|������������}|j��������r||�j��������|<���d�S�|j��������r%||�j��������|j��������<���|j��������D�]}||�j��������|<���� d�S�t ����������j��������d|z���������������#�t����������j��������$�r\}t����������|t����������������������s,t����������j��������t ����������j��������d|z��������������|��������������n||�j��������|<���Y�d�}~d�S�Y�d�}~d�S�d�}~ww�xY�w)Nz!Not an acceptable bind target: %s��replace_context) r���� is_selectabler����� is_mapper�class_�_all_tablesrG���� ArgumentError�NoInspectionAvailabler�����typer���r����)rM���r����rg����insp� selectable�errs��� r"���r����zSession._add_bind]��sB����� ��3�<�<�D���!�� �%)���T�"�"�"���� �,0���T�[�)�"&�"2��4��4�J�/3�D�L��,�,�4��4���*�7�#�=�������%��+�� )�� )�� )��c�4�(�(�� )����(�;�c�A�����%(� ����������%)���S�!�!�!�!�!�!�!���������������� )���s����A'��'C�6AC � Cc������������������2�����|�����������������������||�������������dS�)a���Associate a :class:`_orm.Mapper` or arbitrary Python class with a "bind", e.g. an :class:`_engine.Engine` or :class:`_engine.Connection`. The given entity is added to a lookup used by the :meth:`.Session.get_bind` method. :param mapper: a :class:`_orm.Mapper` object, or an instance of a mapped class, or any Python class that is the base of a set of mapped classes. :param bind: an :class:`_engine.Engine` or :class:`_engine.Connection` object. .. seealso:: :ref:`session_partitioning` :paramref:`.Session.binds` :meth:`.Session.bind_table` N�r����)rM���r��rg���s��� r"����bind_mapperzSession.bind_mapperv��s������4� ���v�t�$�$�$�$�$r*���c������������������2�����|�����������������������||�������������dS�)a���Associate a :class:`_schema.Table` with a "bind", e.g. an :class:`_engine.Engine` or :class:`_engine.Connection`. The given :class:`_schema.Table` is added to a lookup used by the :meth:`.Session.get_bind` method. :param table: a :class:`_schema.Table` object, which is typically the target of an ORM mapping, or is present within a selectable that is mapped. :param bind: an :class:`_engine.Engine` or :class:`_engine.Connection` object. .. seealso:: :ref:`session_partitioning` :paramref:`.Session.binds` :meth:`.Session.bind_mapper` Nr)��)rM����tablerg���s��� r"���� bind_tablezSession.bind_table���s������4� ���u�d�#�#�#�#�#r*���c������������������r����||cxu�r�%n�n"|�j���������r|�j���������S�t����������j��������d�������������|�l �t����������|������������}n[#�t����������j��������$�rI}t����������|t����������������������r)t����������j��������t����������j ��������|������������|��������������n��Y�d}~nd}~ww�xY�w|�j��������re|r0|j��������j ��������D�]}||�j��������v�r|�j��������|���������c�S��|�|j��������}|�1t����������j��������|d�������������D�]}||�j��������v�r|�j��������|���������c�S��|�j���������r|�j���������S�t����������|t"����������j��������j��������������������r|j���������r|j���������S�|r|j��������j���������r|j��������j���������S�g�}|�|���������������������d|z���������������|�|���������������������d�������������t����������j��������dd ���������������������|������������z���������������) al��Return a "bind" to which this :class:`.Session` is bound. The "bind" is usually an instance of :class:`_engine.Engine`, except in the case where the :class:`.Session` has been explicitly bound directly to a :class:`_engine.Connection`. For a multiply-bound or unbound :class:`.Session`, the ``mapper`` or ``clause`` arguments are used to determine the appropriate bind to return. Note that the "mapper" argument is usually present when :meth:`.Session.get_bind` is called via an ORM operation such as a :meth:`.Session.query`, each individual INSERT/UPDATE/DELETE operation within a :meth:`.Session.flush`, call, etc. The order of resolution is: 1. if mapper given and :paramref:`.Session.binds` is present, locate a bind based first on the mapper in use, then on the mapped class in use, then on any base classes that are present in the ``__mro__`` of the mapped class, from more specific superclasses to more general. 2. if clause given and ``Session.binds`` is present, locate a bind based on :class:`_schema.Table` objects found in the given clause present in ``Session.binds``. 3. if ``Session.binds`` is present, return that. 4. if clause given, attempt to return a bind linked to the :class:`_schema.MetaData` ultimately associated with the clause. 5. if mapper given, attempt to return a bind linked to the :class:`_schema.MetaData` ultimately associated with the :class:`_schema.Table` or other selectable to which the mapper is mapped. 6. No bind can be found, :exc:`~sqlalchemy.exc.UnboundExecutionError` is raised. Note that the :meth:`.Session.get_bind` method can be overridden on a user-defined subclass of :class:`.Session` to provide any kind of bind resolution scheme. See the example at :ref:`session_custom_partitioning`. :param mapper: Optional :func:`.mapper` mapped class or instance of :class:`_orm.Mapper`. The bind can be derived from a :class:`_orm.Mapper` first by consulting the "binds" map associated with this :class:`.Session`, and secondly by consulting the :class:`_schema.MetaData` associated with the :class:`_schema.Table` to which the :class:`_orm.Mapper` is mapped for a bind. :param clause: A :class:`_expression.ClauseElement` (i.e. :func:`_expression.select`, :func:`_expression.text`, etc.). If the ``mapper`` argument is not present or could not produce a bind, the given expression construct will be searched for a bound element, typically a :class:`_schema.Table` associated with bound :class:`_schema.MetaData`. .. seealso:: :ref:`session_partitioning` :paramref:`.Session.binds` :meth:`.Session.bind_mapper` :meth:`.Session.bind_table` NzlThis session is not bound to a single Engine or Connection, and no context was provided to locate a binding.r��T)�include_crudz mapper %szSQL expressionz8Could not locate a bind configured on %s or this Session�, )rg���rG����UnboundExecutionErrorr���r#��r����r$��r���r����r����UnmappedClassErrorr����r ���__mro__�persist_selectable�sql_util�find_tablesr���r���� ClauseElement�append�join)rM���r��r ��r'��r(���r�����contexts��� r"���rc���zSession.get_bind���sP�����X��V�#�#�#�#�#�#�#�#��y�� ��y� ��2�!��������� � ��������/�� �� �� ��f�d�+�+����K��.�v�6�6�(+���������� ��������������� ������<�� /��� 7�!�=�0��1��1�C��d�l�*�*�#�|�C�0�0�0�0��+��>�#�6�F��!�!�-�f�4�H�H�H��/��/�A��D�L�(�(�#�|�A��.�.�.��)���9�� ��9���f�c�n�:�;�;�� ���� ��;���� 2�f�/�4�� 2��,�1�1������N�N�;��/�0�0�0����N�N�+�,�,�,��*�F��y�y��!�!� #� �� �� s����A����B�?B�Bc������������������ ������|�j���������||�fi�|��S�)zZReturn a new :class:`_query.Query` object corresponding to this :class:`.Session`.)r����)rM����entitiesr/���s��� r"���r ���z Session.query1��s ��������t��x��8�8��8�8�8r*���c��������������#����V���K����|�j���������}d|�_��������� �|�V���||�_���������dS�#�||�_���������w�xY�w)ag��Return a context manager that disables autoflush. e.g.:: with session.no_autoflush: some_object = SomeClass() session.add(some_object) # won't autoflush some_object.related_thing = session.query(SomeRelated).first() Operations that proceed within the ``with:`` block will not be subject to flushes occurring upon query access. This is useful when initializing a series of objects which involve existing database queries, where the uncompleted object should not yet be flushed. FN)r����)rM���r����s��� r"����no_autoflushzSession.no_autoflush7��sB����������*��N� ���� '��J�J�J�&�D�N�N�N��Y�D�N�&�&�&�&s������ (c����������������������|�j���������r}|�j��������sx �|�������������������������������������d�S�#�t����������j��������$�rM}|���������������������d�������������t ����������j��������|t����������j ����������������������d�����������������������Y�d�}~d�S�d�}~ww�xY�wd�S�d�S�)Nz�raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurelyr���r����) r����rv���rw���rG����StatementError� add_detailr���r����r����r����)rM����es��� r"���� _autoflushzSession._autoflushS��s��������>�� A�$�.�� A� A�� � ��������(�� A�� A�� A� ����5������ ���A�c�l�n�n�Q�.?�@�@�@�@�@�@�@�@�@�@����� A���� A�� A�� A�� As����&��B�AA=�=Bc���������������������� �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|����������������������||�������������|i�k����rt����������j ��������d�������������|r t����������j�����������������������������|������������}n0|�.|du�rt����������j����������������������}n|rt����������j��������di�|��}nd}t����������j��������|�� ��������������������t����������|������������������������|j��������|||������������� ��$t����������j��������dt%����������|������������z���������������dS�)a{��Expire and refresh the attributes on the given instance. A query will be issued to the database and all attributes will be refreshed with their current database value. Lazy-loaded relational attributes will remain lazily loaded, so that the instance-wide refresh operation will be followed immediately by the lazy load of that attribute. Eagerly-loaded relational attributes will eagerly load within the single refresh operation. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction - usage of :meth:`~Session.refresh` usually only makes sense if non-ORM SQL statement were emitted in the ongoing transaction, or if autocommit mode is turned on. :param attribute_names: optional. An iterable collection of string attribute names indicating a subset of attributes to be refreshed. :param with_for_update: optional boolean ``True`` indicating FOR UPDATE should be used, or may be a dictionary containing flags to indicate a more specific set of FOR UPDATE flags for the SELECT; flags should match the parameters of :meth:`_query.Query.with_for_update`. Supersedes the :paramref:`.Session.refresh.lockmode` parameter. .. versionadded:: 1.2 :param lockmode: Passed to the :class:`~sqlalchemy.orm.query.Query` as used by :meth:`~sqlalchemy.orm.query.Query.with_lockmode`. Superseded by :paramref:`.Session.refresh.with_for_update`. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.expire_all` :meth:`_orm.Query.populate_existing` r��Nzqwith_for_update should be the boolean value True, or a dictionary with options. A blank dictionary is ambiguous.T)� refresh_state�with_for_update�only_load_propszCould not refresh instance '%s'r:���)r����instance_stater����NO_STATEr���r�����UnmappedInstanceError� _expire_staterG���r"��r ����LockmodeArg�parse_legacy_queryr���� load_on_identr���r����rH���r���)rM���r2����attribute_namesrF���lockmoder���r'��s��� r"���r����zSession.refreshc��s������l ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ����� ���5�/�2�2�2��b� � ��&�3����� ���� '�#�/�B�B�8�L�L�O�O� � (��$�&�&�"'�"3�"5�"5��� �� '�"'�"3�"F�"F�o�"F�"F���"&��� �!�� � �=��2�2�3�3�� �#� /� /� �� �� ��� ���,�1�L��4J�4J�J����� � �� �������A�(A�Ac�����������������������|�j��������������������������������������������D�]'}|���������������������|j��������|�j���������j����������������������(dS�)a���Expires all persistent instances within this Session. When any attributes on a persistent instance is next accessed, a query will be issued using the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire individual objects and individual attributes on those objects, use :meth:`Session.expire`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire_all` should not be needed when autocommit is ``False``, assuming the transaction is isolated. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` :meth:`_orm.Query.populate_existing` N)r����r����r����r����r�����rM���r���s��� r"���r����zSession.expire_all���sP������@��&�1�1�3�3�� C�� C�E��M�M�%�*�d�&7�&A�B�B�B�B� C�� Cr*���c������������������������ �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|����������������������||�������������dS�)a���Expire the attributes on an instance. Marks the attributes of an instance as out of date. When an expired attribute is next accessed, a query will be issued to the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire all objects in the :class:`.Session` simultaneously, use :meth:`Session.expire_all`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire` only makes sense for the specific case that a non-ORM SQL statement was emitted in the current transaction. :param instance: The instance to be refreshed. :param attribute_names: optional list of string attribute names indicating a subset of attributes to be expired. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` :meth:`_orm.Query.populate_existing` r��N)r���rH��r���rI��r���r����rJ��rK��)rM���r2���rO��r���r'��s��� r"���r����zSession.expire���s�������J ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ���� � ���5�/�2�2�2�2�2rQ��c������������������0����|�����������������������|�������������|r|���������������������|j��������|�������������d�S�t����������|j��������j�����������������������������d|������������������������}|����������������������|�������������|D�]\��}}}}|����������������������|��������������d�S�)Nzrefresh-expire)�_validate_persistent�_expire_attributesr����r�����managerr���cascade_iterator�_conditional_expire)rM���r���rO���cascaded�o�m�st_�dct_s��� r"���rK��zSession._expire_state��s��������!�!�%�(�(�(��� .��$�$�U�Z��A�A�A�A�A���� �$�5�5�6F��N�N����H�� �$�$�U�+�+�+�#+�� .�� .���1�c�4��(�(��-�-�-�-� .�� .r*���c������������������������|j���������r'|���������������������|j��������|�j��������j���������������������dS�||�j��������v�r1|�j�����������������������������|�������������|���������������������|��������������dS�dS�)z5Expire a state if persistent, else expunge if pendingN)r����r����r����r����r����rr����pop�_detachrS��s��� r"���rZ��zSession._conditional_expire!��sq��������9�� ��M�M�%�*�d�&7�&A�B�B�B�B�B� �d�i� � ��I�M�M�%� � � ��M�M�$������� � r*���r����z�The :meth:`.Session.prune` method is deprecated along with :paramref:`.Session.weak_identity_map`. This method will be removed in a future release.c������������������4�����|�j��������������������������������������������S�)a���Remove unreferenced instances cached in the identity map. Note that this method is only meaningful if "weak_identity_map" is set to False. The default weak identity map is self-pruning. Removes any object in this Session's identity map that is not referenced in user code, modified, new or scheduled for deletion. Returns the number of objects pruned. )r�����prunerQ���s��� r"���rd��z Session.prune*��s������"�� �&�&�(�(�(r*���c���������������������� �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|j��������|�j��������ur$t����������j ��������dt����������|������������z���������������t����������|j ��������j�����������������������������d|������������������������}|����������������������|gd��|D���������������z����������������dS�)z�Remove the `instance` from this ``Session``. This will free all internal references to the instance. Cascading will be applied according to the *expunge* cascade rule. r��Nz*Instance %s is not present in this Sessionr����c�����������������������g�|�] \��}}}}|�� S�r:���r:���)�.0r\��r]��r^��r_��s��� r"���� <listcomp>z#Session.expunge.<locals>.<listcomp>S��s ������'L�'L�'L���1�c�4��'L�'L�'Lr*���)r���rH��r���rI��r���r����rJ��r���r����rG���rH���r���r����rX��r��rY��r����)rM���r2���r���r'��r[��s��� r"���r����zSession.expunge=��s����� ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ���� ���4�=�0�0��,�<�y��?O�?O�O����� ����M� �1�1�)�U�C�C� �� ��� ���e�W�'L�'L�8�'L�'L�'L�L�M�M�M�M�MrQ��c����������������������|D�]�}||�j���������v�r|�j������������������������������|��������������&|�j�����������������������������|������������r6|�j�����������������������������|�������������|�j�����������������������������|d���������������v|�j��������r |�j��������j�����������������������������|d����������������t����������j��������� ��������������������||�|��������������d�S�)Nr{���) rr���ra��r�����contains_stater����rs���r����r����r����r����)rM����statesr|���r���s��� r"���r����zSession._expunge_statesU��s��������� ;�� ;�E��� �!�!�� � � �e�$�$�$�$��"�1�1�%�8�8�� ;��!�.�.�u�5�5�5�� �!�!�%��.�.�.�.��!�� ;��� �)�-�-�e�T�:�:�:����-�-��D�|�� .�� �� �� �� �� r*���c����������������������|�j���������j��������pd}|D��]}t����������|������������}|�����������������������������������}|��V|���������������������|������������}t����������j��������|d���������������������r|j��������rt����������j��������|d���������������������r$t����������j ��������dt����������|������������z���������������|j���������||_��������nk|j��������|k����r`|�j �����������������������������|�������������||�j��������j��������v�r|�j��������j��������|���������d���������}n|j��������}||f|�j��������j��������|<���||_��������|�j �����������������������������|������������}|�E|���������������������|������������|k����r,|������������������������������������t%����������j��������d|�d��������������d|_�����������t*����������j�����������������������������d��|D���������������|�j ���������������������|����������������������|�������������|�)|���������������������|�j��������������������D�]}�||�|��������������t5����������|���������������������������������|�j��������������������D�]}|�j�����������������������������|��������������dS�) z�Register all persistent objects from a flush. This is used both for pending objects moving to the persistent state as well as already persistent objects. Nr���aO��Instance %s has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.r���z)Identity map already had an identity for z|, replacing it with newly flushed object. Are there load operations occurring inside of an event handler within the flush?Fc��������������3����(���K����|�] }||j���������fV����d�S�rS����r�����rg��r���s��� r"���� <genexpr>z/Session._register_persistent.<locals>.<genexpr>���s)����������5�5�U�e�U�Z� �5�5�5�5�5�5r*���)rK����pending_to_persistentr����obj�_identity_key_from_stater ����intersection�allow_partial_pks� issupersetr���r����r���r����r����r����r����ru���r����r���r�����_orphaned_outside_of_sessionr����r�����_commit_all_states�_register_alteredrr���r~���ra��) rM���rk��rq��r���r��rr���instance_key�orig_key�olds ��� r"����_register_persistentzSession._register_persistentd��s�������!%� � C� K�t����9 ;��9 ;�E�"�5�)�)�F���)�)�+�+�C���%�>�>�u�E�E����*�<��?�;�;��"�4���!�+�L��O�<�<�� ��.�?��$�E�*�*�+� �� �� ���9�$� ,�E�I�I��Y�,�.�.���%�2�2�5�9�9�9��� 0� >�>�>�#'�#3�#A�%�#H��#K���#(�9�� �$�=�D�$�2�5�9��!-�E�I� ��'�/�/��6�6���O��7�7��<�<��L�L���� � �-��I�I��0<�|�|�>�������6;��2����1�1�5�5�f�5�5�5�t�7H� �� �� �� ���v�&�&�&� �,��,�,�T�Y�7�7�� 3�� 3��%�%�d�E�2�2�2�2����[�[�-�-�d�i�8�8�� !�� !�E��I�M�M�%� � � � � !�� !r*���c�����������������������|�j���������r4|�j��������r/|D�].}||�j��������v�rd|�j��������j��������|<����d|�j��������j��������|<����+d�S�d�S�d�S��NT)rI���r����rr���rt���)rM���rk��r���s��� r"���ry��zSession._register_altered���sw�������.�� :�4�3C�� :��� :�� :���D�I�%�%�37�D�$�)�%�0�0�59�D�$�+�E�2�2� :�� :�� :�� :� :�� :r*���c������������������&����|�j���������j��������pd�}|D�]}|�j��������r|�j��������rd|�j��������j��������|<���|�|�����������������������������������}|�j�����������������������������|�������������|�j�����������������������������|d��������������d|_��������|��||�|���������������d�S�r��) rK����persistent_to_deletedrI���r����rs���rr��r����r����ra��)rM���rk��r���r���rr��s��� r"����_remove_newly_deletedzSession._remove_newly_deleted���s������� $� � C� K�t���� 3�� 3�E��2�� 8�t�7G�� 8�37�� �)�%�0�$�0���i�i�k�k����*�*�5�1�1�1��M���e�T�*�*�*�!�E�N��%�0�%�%�d�E�2�2�2��! 3�� 3r*���c������������������ ����|r|�j���������r|����������������������d������������� �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t ����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|�� ��������������������|�������������dS�)z�Place an object in the ``Session``. Its state will be persisted to the database on the next flush operation. Repeated calls to ``add()`` will be ignored. The opposite of ``add()`` is ``expunge()``. z Session.add()r��N) r�����_flush_warningr���rH��r���rI��r���r����rJ���_save_or_update_state)rM���r2����_warnr���r'��s��� r"���r����zSession.add���s���������� 1�T�)�� 1�����0�0�0� ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ����� �"�"�5�)�)�)�)�)s����5��A6�(A1�1A6c������������������v�����|�j���������r|����������������������d�������������|D�]}|����������������������|d���������������dS�)z:Add the given collection of instances to this ``Session``.zSession.add_all()F)r���N)r����r���r����)rM���� instancesr2���s��� r"���r����zSession.add_all���sV���������� 5���� 3�4�4�4�!�� ,�� ,�H��H�H�X�U�H�+�+�+�+� ,�� ,r*���c������������������������d|_���������|����������������������|�������������t����������|������������}|���������������������d||�j���������������������D�]\��}}}}|����������������������|��������������d�S�)NFzsave-update)�halt_on)rw���_save_or_update_implr���rY���_contains_state)rM���r���r��r\��r]��r^��r_��s��� r"���r���zSession._save_or_update_state���s�������-2��*��!�!�%�(�(�(��u�%�%��%�6�6��5�$�*>�� 7�� �� �� +�� +�O�A�q�#�t�� �%�%�c�*�*�*�*� +�� +r*���c������������������"����|�j���������r|����������������������d������������� �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t ����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|�� ��������������������||d��������������dS�)zfMark an instance as deleted. The database delete operation occurs upon ``flush()``. zSession.delete()r��NT)�head) r����r���r���rH��r���rI��r���r����rJ���_delete_impl�rM���r2���r���r'��s��� r"���r����zSession.delete���s����������� 4���� 2�3�3�3� ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ����� ���%����5�5�5�5�5s����3��A4�(A/�/A4c�����������������������|j����������(|r$t����������j��������dt����������|������������z���������������d�S�|����������������������||������������}||�j��������v�rd�S�|�j�����������������������������|�������������|r|����������������������||�������������|r-t����������|j ��������j�����������������������������d|������������������������}||�j��������|<���|r!|D�] \��}}}} |�� ��������������������||d��������������d�S�d�S�)N�Instance '%s' is not persistedr����F)r����rG���rH���r����_before_attachrs���r����r����� _after_attachr����rX��r��rY��r���) rM���r���rr��r���� to_attach�cascade_statesr\��r]��r^��r_��s ��� r"���r���zSession._delete_impl��s'������9���� ��0�4�y��7G�7G�G����������'�'��s�3�3� ��D�M�!�!��F�����e�$�$�$��� +����u�c�*�*�*��� ��"�� �$�5�5�h��F�F����N�� #�� �e���� 1�#1�� 1�� 1���1�c�4��!�!�#�q�%�0�0�0�0� 1�� 1� 1�� 1r*���c������������������L����|�j���������r|����������������������d�������������i�}i�}|r|�������������������������������������t����������|�������������|�j��������} �d|�_��������|����������������������t ����������j��������|������������t ����������j��������|������������|||�������������||�_��������S�#�||�_��������w�xY�w)a� ��Copy the state of a given instance into a corresponding instance within this :class:`.Session`. :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. .. versionchanged:: 1.1 - :meth:`.Session.merge` will now reconcile pending objects with overlapping primary keys in the same way as persistent. See :ref:`change_3601` for discussion. :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. .. seealso:: :func:`.make_transient_to_detached` - provides for an alternative means of "merging" a single object into the :class:`.Session` zSession.merge()F)�load� _recursive�_resolve_conflict_map) r����r���rC��r���r�����_merger���rH��� instance_dict)rM���r2���r���r���r���r����s��� r"���r����z Session.merge1��s�������n���� 3���� 1�2�2�2�� � "���� ��O�O�����h�����N� � '�"�D�N��;�;��)�(�3�3��(��2�2��%�&;��������'�D�N�N��Y�D�N�&�&�&�&s ����AB�� B#c�����������������������t����������|������������}||v�r||���������S�d}|j��������}|��||�j��������v�r$t����������j��������dt����������|������������z���������������|st ����������j��������d�������������|���������������������|������������}t����������j ��������|d���������vo<t����������j��������|d����������������������p!|j ��������ot����������j��������|d����������������������} nd} ||�j��������v�r! �|�j��������|���������} n#�t ����������$�r�d�} Y�nw�xY�wd�} | ��| r ||v�r ||���������} n�|sg|j��������rt ����������j��������d�������������|j�������������������������������������������} t����������j��������| ������������}||_��������|����������������������|�������������d}n5| r3|����������������������|j�����������������������������������������|d���������������������} | �Y|j�������������������������������������������} t����������j��������| ������������}t����������j��������| ������������}d}|����������������������|�������������n(t����������j��������| ������������}t����������j��������| ������������}| ||<���| ||<���||ur�|j����������|���������������������|||j��������t����������j���������������������} |���������������������|||j��������t����������j���������������������}| t����������j��������ur?|t����������j��������ur1| |k����r+t?����������j ��������d| �d t����������|�������������d |�d��������������|j!��������|_!��������|j"��������|_"��������|�#��������������������|�������������|j$��������D�]}|�%��������������������|�|||||||��������������|s|�&��������������������||�j���������������������|r |j'��������j(���������)��������������������|d��������������| S�)NFzrInstance %s is already pending in this Session yet is being merged again; this is probably not what you want to doz�merge() with load=False option does not support objects transient (i.e. unpersisted) objects. flush() all changes on mapped instances before merging with load=False.r���Tz�merge() with load=False option does not support objects marked as 'dirty'. flush() all changes on mapped instances before merging with load=False.��passivezVersion id 'z' on merged state z" does not match existing version 'zT'. Leave the version attribute unset when merging to update the most recent version.)*r���r����rr���r���r����r���rG���rH���rs��r���� NEVER_SETr ���rt��ru��rv��r����r!���r����� class_manager�new_instancerH��r����r ���r ���getr���r����version_id_col�_get_state_attr_by_column�PASSIVE_NO_INITIALIZE�PASSIVE_NO_RESULTr����StaleDataError� load_path�load_options�_copy_callables�iterate_propertiesr�����_commit_allrX��rK���r���)rM���r���� state_dictr���r���r���r��r���r�����key_is_persistent�merged�merged_state�merged_dict�existing_version�merged_version�props��� r"���r���zSession._merge���s?�������u�%�%���J����e�$�$����i���;��� �!�!�� ��'��.�.�/��������� ��0�"��������1�1�%�8�8�C� *� 4�C��F� B��!��*�3�q�6�2�2�2����,��9�%�0��Q��8�8�8� � ���!%���$�#�#�#� ��*�3�/������ �� �� ����� ������F��>� �� ?�S�,A�%A�%A�.�s�3����� ?��>��� �4�K������ � �-�:�:�<�<��)�8��@�@��#&�� ��!�!�,�/�/�/�#���"�� ?����F�M�2�2�6�6�s�1�v�>�>���>��)�6�6�8�8�F�%�4�V�<�<�L�$�2�6�:�:�K��L��&�&�|�4�4�4�4�%�4�V�<�<�L�$�2�6�:�:�K�"� �5��%+��c�"����$�$��$�0�#)�#C�#C����)�&�<� �$D��$��$� ��"(�!A�!A� ���)�&�<� �"B��"��"���%�J�,H�H�H�&�j�.J�J�J�(�N�:�:��,�,��-�,�,�%�l�3�3�3�3�*�N�N�� �� �� ��&+�_�L�"�(-�(:�L�%�� �(�(��/�/�/��1�� �� ��� � ���� ����)� �� �� �� ���� E��$�$�[�$�2C�D�D�D��� C�� �)�.�.�|�T�B�B�B�� s���� C+��+C:�9C:c�����������������������|�j������������������������������|������������s$t����������j��������dt ����������|������������z���������������d�S�)Nz3Instance '%s' is not persistent within this Session)r����rj��rG���rH���r���rS��s��� r"���rV��zSession._validate_persistent ��sM������� �/�/��6�6�� ��,�E��E�"�"�#����� � �� r*���c������������������<����|j����������$t����������j��������dt����������|������������z���������������|�����������������������������������}|����������������������||������������}||�j��������vr#||�j��������|<���t����������|�j��������������������|_��������|r|�� ��������������������||�������������d�S�d�S�)NzGObject '%s' already has an identity - it can't be registered as pending) r����rG���rH���r���rr��r���rr����len�insert_orderr���)rM���r���rr��r���s��� r"���� _save_implzSession._save_impl ��s��������9� ��,�4�6?��6F�6F�G����� � ��i�i�k�k���'�'��s�3�3� ��� �!�!�"�D�I�e��!$�T�Y���E���� +����u�c�*�*�*�*�*� +�� +r*���c������������������@����|j����������$t����������j��������dt����������|������������z���������������|j��������r2|r|j��������sd�S�|`n$t����������j��������dt����������|������������z���������������|�����������������������������������}|�d�S�|����������������������||������������}|�j�����������������������������|d��������������|r|�j ��������� ��������������������|�������������n|�j �����������������������������|�������������|r|����������������������||�������������d�S�|r|�j �����������������������������|�|�������������d�S�d�S�)Nr���zsInstance '%s' has been deleted. Use the make_transient() function to send this object back to the transient state.)r����rG���rH���r���rs���� _attachedrr��r���ra��r����r����r����r���rK����deleted_to_persistent)rM���r���r}���rr��r���s��� r"���r����zSession._update_impl+ ��s[������9���,�0�9�U�3C�3C�C����� ���>�� ��� ������F��N�N��0�.��1:�%�0@�0@�A��������i�i�k�k����;��F��'�'��s�3�3� �� ���%��&�&�&��� )���%�%�e�,�,�,�,���!�!�%�(�(�(��� =����u�c�*�*�*�*�*� �� =��M�/�/��e�<�<�<�<�<� =�� =r*���c������������������l�����|j����������|����������������������|�������������d�S�|����������������������|�������������d�S�rS���)r����r���r����rS��s��� r"���r���zSession._save_or_update_implQ ��s<�������9���O�O�E�"�"�"�"�"����e�$�$�$�$�$r*���c�����������������������t����������j��������|������������}|����������������������||������������}d|_��������|r|����������������������||�������������dS�dS�)a ��Associate an object with this :class:`.Session` for related object loading. .. warning:: :meth:`.enable_relationship_loading` exists to serve special use cases and is not recommended for general use. Accesses of attributes mapped with :func:`_orm.relationship` will attempt to load a value from the database using this :class:`.Session` as the source of connectivity. The values will be loaded based on foreign key and primary key values present on this object - if not present, then those relationships will be unavailable. The object will be attached to this session, but will **not** participate in any persistence operations; its state for almost all purposes will remain either "transient" or "detached", except for the case of relationship loading. Also note that backrefs will often not work as expected. Altering a relationship-bound attribute on the target object may not fire off a backref event, if the effective value is what was already loaded from a foreign-key-holding value. The :meth:`.Session.enable_relationship_loading` method is similar to the ``load_on_pending`` flag on :func:`_orm.relationship`. Unlike that flag, :meth:`.Session.enable_relationship_loading` allows an object to remain transient while still being able to load related items. To make a transient object associated with a :class:`.Session` via :meth:`.Session.enable_relationship_loading` pending, add it to the :class:`.Session` using :meth:`.Session.add` normally. If the object instead represents an existing identity in the database, it should be merged using :meth:`.Session.merge`. :meth:`.Session.enable_relationship_loading` does not improve behavior when the ORM is used normally - object references should be constructed at the object level, not at the foreign key level, so that they are present in an ordinary way before flush() proceeds. This method is not intended for general use. .. seealso:: :paramref:`_orm.relationship.load_on_pending` - this flag allows per-relationship loading of many-to-ones on items that are pending. :func:`.make_transient_to_detached` - allows for an object to be added to a :class:`.Session` without SQL emitted, which then will unexpire attributes on access. TN)r���rH��r���� _load_pendingr���)rM���rr��r���r���s��� r"����enable_relationship_loadingz#Session.enable_relationship_loadingW ��s`������n��)�#�.�.���'�'��s�3�3� �"����� +����u�c�*�*�*�*�*� +�� +r*���c����������� �������������|j���������|�j��������k����rdS�|j���������rC|j���������t����������v�r5t����������j��������dt����������|�������������d|j����������d|�j���������d��������������|�j�����������������������������|�|�������������dS�)NFzObject 'z"' is already attached to session 'z' (this is 'z')T)r���r����r ���rG���rH���r���rK���� before_attach�rM���r���rr��s��� r"���r���zSession._before_attach� ��s���������t�}�,�,��5���� �� 0�I� =� =��,�,���U�#�#�#�#�U�%5�%5�%5�t�}�}�}�F����� �� � �#�#�D�%�0�0�0��tr*���c�����������������������|�j���������|_��������|j��������r|j���������||_��������|�j�����������������������������|�|�������������|j��������r|�j�����������������������������|�|�������������d�S�|�j�����������������������������|�|�������������d�S�rS���) r����r���r�����_strong_objrK����after_attachr�����detached_to_persistent�transient_to_pendingr���s��� r"���r���zSession._after_attach� ��s��������=����>�� $�e�/�7� #�E��� �"�"�4��/�/�/��9�� <��M�0�0��u�=�=�=�=�=��M�.�.�t�U�;�;�;�;�;r*���c������������������������ �t����������j��������|������������}nD#�t����������j��������$�r2}t ����������j��������t����������j��������|������������|��������������Y�d}~nd}~ww�xY�w|����������������������|������������S�)z�Return True if the instance is associated with this session. The instance may be pending or persistent within the Session for a result of True. r��N)r���rH��r���rI��r���r����rJ��r���r���s��� r"���r����zSession.__contains__� ��s������� ��-�h�7�7�E�E���|�� �� �� ��K��)�(�3�3� #� �� �� �� �� �� �� �� �� ����� ���� ��#�#�E�*�*�*rQ��c�����������������������t����������t����������|�j�������������������������������������������������������t����������|�j�������������������������������������������������������z���������������S�)zWIterate over all pending or persistent instances within this Session. )�iterr����rr���r����r����rQ���s��� r"���r����zSession.__iter__� ��sK������ �����!�!�#�#�$�$�t�D�,=�,D�,D�,F�,F�'G�'G�G� �� �� r*���c������������������H�����||�j���������v�p|�j�����������������������������|������������S�rS���)rr���r����rj��rS��s��� r"���r���zSession._contains_state� ��s%�������� �!�L�T�%6�%E�%E�e�%L�%L�Lr*���c������������������������|�j���������rt����������j��������d�������������|������������������������������������rdS� �d|�_���������|����������������������|�������������d|�_���������dS�#�d|�_���������w�xY�w)a���Flush all the object changes to the database. Writes out all pending object creations, deletions and modifications to the database as INSERTs, DELETEs, UPDATEs, etc. Operations are automatically ordered by the Session's unit of work dependency solver. Database operations will be issued in the current transactional context and do not affect the state of the transaction, unless an error occurs, in which case the entire transaction is rolled back. You may flush() as often as you like within a transaction to move changes from Python to the database's transaction buffer. For ``autocommit`` Sessions with no active manual transaction, flush() will create a transaction on the fly that surrounds the entire set of operations into the flush. :param objects: Optional; restricts the flush operation to operate only on elements that are in the given collection. This feature is for an extremely narrow set of use cases where particular objects may need to be operated upon before the full flush() occurs. It is not intended for general use. zSession is already flushingNTF)rv���rG���rH���r�����_flush)rM����objectss��� r"���rw���z Session.flush� ��st������6��>�� L��,�-J�K�K�K��>�>���� ��F� #�!�D�N��K�K�� � � �"�D�N�N�N��U�D�N�"�"�"�"s����A�� A!c������������������4�����t����������j��������d|z���������������d�S�)Nz�Usage of the '%s' operation is not currently supported within the execution stage of the flush process. Results may not be consistent. Consider using alternative event listeners or connection-level operations instead.)r���r����)rM����methods��� r"���r���zSession._flush_warning� ��s3������� � F��IO� O� �� �� �� �� r*���c������������������V�����|�j���������������������������������������������o|�j���������o|�j���������S�rS���)r�����check_modifiedrs���rr���rQ���s��� r"���r����zSession._is_clean� ��s5�������!�0�0�2�2�2�� ��M�!� ��I� � r*���c������������������N����|�j���������}|s.|�j��������s'|�j��������s |�j��������j��������������������������������������������d�S�t ����������|�������������}|�j��������j��������r#|�j�����������������������������|�||�������������|�j���������}t����������|�j��������������������}t����������|�j��������������������}t����������|������������� ��������������������|������������}|r�t������������������������}|D�]q} �t����������j��������|������������}nD#�t����������j��������$�r2} t����������j��������t����������j��������|������������| ��������������Y�d�} ~ nd�} ~ ww�xY�w|���������������������|��������������rnd�}t������������������������} |r<|���������������������|���������������������������������|������������� ��������������������|������������}n(|���������������������|������������� ��������������������|������������}|D�]�}t+����������|���������������������������������|������������}|o|j��������} |r | s|j��������r|����������������������|g��������������O|���������������������|| �������������}|s J�d���������������| ���������������������|���������������|r)|���������������������|������������� ��������������������| ������������}n|� ��������������������| ������������}|D�]%}|���������������������|d�������������}|s J�d����������������&|j��������sd�S�|����������������������d�������������x|_��������} �d|�_�������� �|������������������������������������d|�_��������n#�d|�_��������w�xY�w|�j��������� ��������������������|�|�������������|�!�����������������������������������|sv|�j��������j��������rjtE����������|�j��������j��������������������}tF����������j$���������%��������������������d��|�j��������j��������D���������������|�j����������������������t����������j&��������d |z���������������|�j���������'��������������������|�|�������������|�(�����������������������������������d�S�#��t����������j)����������������������5��|�*��������������������d� �������������d�d�d��������������Y�d�S�#�1�swxY�w�Y���Y�d�S�xY�w)Nr��)�isdeletez*Failed to add object to the flush context!T�r��Fc������������������ �����g�|�]}||j���������f��S�r:���rn��ro��s��� r"���rh��z"Session._flush.<locals>.<listcomp>^ ��s/������������!���� �+�����r*���)r���z�Attribute history events accumulated on %d previously clean instances within inner-flush event handlers have been reset, and will not result in database updates. Consider using set_committed_value() within inner-flush event handlers to avoid this warning.�r����)+� _dirty_statesrs���rr���r����r����r����r���rK����before_flushr~���� differencer���rH��r���rI��r���r����rJ��r����r���rt��r���� _is_orphan�has_identityrw��r�����register_object�has_workr����r����r����r�����after_flush�finalize_flush_changesr���r����r����rx��r�����after_flush_postexecr����r����r����)rM���r����dirty� flush_context�deleted�new�objsetr\��r���r'��� processed�proc� is_orphan�is_persistent_orphan�_regr�����len_s��� r"���r���zSession._flush� ��s"������"���� �T�]�� �4�9�� ���'�-�-�/�/�/��F�&�t�,�,� ��=�%�� '��M�&�&�t�]�G�D�D�D���&�E��d�m�$�$���$�)�n�n���E� � �%�%�g�.�.����� ��U�U�F��� "�� "���&�5�a�8�8�E�E���|��������K��1�!�4�4�(+�������������������������� �� � �5�!�!�!�!� "���F���E�E� ���� 8��9�9�U�#�#�0�0��8�8�C�C�G�L�L�D�D��9�9�U�#�#�.�.�w�7�7�D��� %�� %�E�%�e�,�,�7�7��>�>�I�#,�#C��1C� ��� %�,� %���6� %� ��$�$�e�W�-�-�-�-�$�4�4��$8��5��������I�I�I�I�I�I�� � �e�$�$�$�$���� 1��'�'��/�/�:�:�9�E�E�D�D��%�%�i�0�0�D��� F�� F�E� �0�0���0�F�F�D��E�E�E�E�E�E�E��%�� ��F�26�*�*� ��3=��3 ��3 �� � �!�K�+ >�#'�D� � -��%�%�'�'�'�',��$�$��u��$�,�,�,�,��M�%�%�d�M�:�:�:��0�0�2�2�2��� �t�0�:�� ��4�,�6�7�7���&�9�9����%)�%6�%@�������#'�"3��:��������� �H� �KO�O������ � �M�.�.�t�]�C�C�C���� � � � � �� >��"�$�$�� >�� >��$�$��$�=�=�=� >�� >�� >�� >�� >�� >�� >�� >�� >�� >�� >�� >�� >����� >�� >�� >�� >�� >�� >�� >���sa����C*�*D+�9(D&�&D+�O��K8��0O��8 L�CO��P$�1P�P$�P �P$�P �P$c����������� ������������d��}d��|D���������������}|st����������||�������������}t����������j��������||������������D�]#\��\��}}} |����������������������|| |d||d��������������$dS�)a���Perform a bulk save of the given list of objects. The bulk save feature allows mapped objects to be used as the source of simple INSERT and UPDATE operations which can be more easily grouped together into higher performing "executemany" operations; the extraction of data from the objects is also performed using a lower-latency process that ignores whether or not attributes have actually been modified in the case of UPDATEs, and also ignores SQL expressions. The objects as given are not added to the session and no additional state is established on them, unless the ``return_defaults`` flag is also set, in which case primary key attributes and server-side default values will be populated. .. versionadded:: 1.0.0 .. warning:: The bulk save feature allows for a lower-latency INSERT/UPDATE of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw INSERT/UPDATES of records. **Please read the list of caveats at** :ref:`bulk_operations_caveats` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param objects: a sequence of mapped object instances. The mapped objects are persisted as is, and are **not** associated with the :class:`.Session` afterwards. For each object, whether the object is sent as an INSERT or an UPDATE is dependent on the same rules used by the :class:`.Session` in traditional operation; if the object has the :attr:`.InstanceState.key` attribute set, then the object is assumed to be "detached" and will result in an UPDATE. Otherwise, an INSERT is used. In the case of an UPDATE, statements are grouped based on which attributes have changed, and are thus to be the subject of each SET clause. If ``update_changed_only`` is False, then all attributes present within each object are applied to the UPDATE statement, which may help in allowing the statements to be grouped together into a larger executemany(), and will also reduce the overhead of checking history on attributes. :param return_defaults: when True, rows that are missing values which generate defaults, namely integer primary key defaults and sequences, will be inserted **one at a time**, so that the primary key value is available. In particular this will allow joined-inheritance and other multi-table mappings to insert correctly without the need to provide primary key values ahead of time; however, :paramref:`.Session.bulk_save_objects.return_defaults` **greatly reduces the performance gains** of the method overall. :param update_changed_only: when True, UPDATE statements are rendered based on those attributes in each state that have logged changes. When False, all attributes present are rendered into the SET clause with the exception of primary key attributes. :param preserve_order: when True, the order of inserts and updates matches exactly the order in which the objects are given. When False, common types of objects are grouped into inserts and updates, to allow for more batching opportunities. .. versionadded:: 1.3 .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_insert_mappings` :meth:`.Session.bulk_update_mappings` c������������������"�����|�j���������|�j��������d�ufS�rS���)r��r����r ���s��� r"���r����z&Session.bulk_save_objects.<locals>.key� ��s�������L�%�)�4�"7�8�8r*���c��������������3����>���K����|�]}t����������j��������|������������V����d�S�rS���)r���rH��)rg��rr��s��� r"���rp��z,Session.bulk_save_objects.<locals>.<genexpr>� ��s-����������H�H��j�/��4�4�H�H�H�H�H�Hr*���)r����TFN)�sorted� itertools�groupby�_bulk_save_mappings) rM���r����return_defaults�update_changed_only�preserve_orderr����� obj_statesr���isupdaterk��s ��� r"���r����zSession.bulk_save_objects| ��s�������n 9�� 9�� 9��I�H��H�H�H� ��� 5�� ��4�4�4�J�*3�*;�J��*L�*L�� �� �&��V�X���$�$������#�� �� �� �� � �� r*���c����������� �������<�����|�����������������������||dd|d|�������������dS�)aF��Perform a bulk insert of the given list of mapping dictionaries. The bulk insert feature allows plain Python dictionaries to be used as the source of simple INSERT operations which can be more easily grouped together into higher performing "executemany" operations. Using dictionaries, there is no "history" or session state management features in use, reducing latency when inserting large numbers of simple rows. The values within the dictionaries as given are typically passed without modification into Core :meth:`_expression.Insert` constructs, after organizing the values within them across the tables to which the given mapper is mapped. .. versionadded:: 1.0.0 .. warning:: The bulk insert feature allows for a lower-latency INSERT of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw INSERT of records. **Please read the list of caveats at** :ref:`bulk_operations_caveats` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param mapper: a mapped class, or the actual :class:`_orm.Mapper` object, representing the single kind of object represented within the mapping list. :param mappings: a sequence of dictionaries, each one containing the state of the mapped row to be inserted, in terms of the attribute names on the mapped class. If the mapping refers to multiple tables, such as a joined-inheritance mapping, each dictionary must contain all keys to be populated into all tables. :param return_defaults: when True, rows that are missing values which generate defaults, namely integer primary key defaults and sequences, will be inserted **one at a time**, so that the primary key value is available. In particular this will allow joined-inheritance and other multi-table mappings to insert correctly without the need to provide primary key values ahead of time; however, :paramref:`.Session.bulk_insert_mappings.return_defaults` **greatly reduces the performance gains** of the method overall. If the rows to be inserted only refer to a single table, then there is no reason this flag should be set as the returned default information is not used. :param render_nulls: When True, a value of ``None`` will result in a NULL value being included in the INSERT statement, rather than the column being omitted from the INSERT. This allows all the rows being INSERTed to have the identical set of columns which allows the full set of rows to be batched to the DBAPI. Normally, each column-set that contains a different combination of NULL values than the previous row must omit a different series of columns from the rendered INSERT statement, which means it must be emitted as a separate statement. By passing this flag, the full set of rows are guaranteed to be batchable into one batch; the cost however is that server-side defaults which are invoked by an omitted column will be skipped, so care must be taken to ensure that these are not necessary. .. warning:: When this flag is set, **server side default SQL values will not be invoked** for those columns that are inserted as NULL; the NULL value will be sent explicitly. Care must be taken to ensure that no server-side default functions need to be invoked for the operation as a whole. .. versionadded:: 1.1 .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_save_objects` :meth:`.Session.bulk_update_mappings` FN�r���)rM���r���mappingsr����render_nullss��� r"���r����zSession.bulk_insert_mappings� ��s<������v� � � �������� �� �� �� �� r*���c����������� �������<�����|�����������������������||ddddd�������������dS�)a���Perform a bulk update of the given list of mapping dictionaries. The bulk update feature allows plain Python dictionaries to be used as the source of simple UPDATE operations which can be more easily grouped together into higher performing "executemany" operations. Using dictionaries, there is no "history" or session state management features in use, reducing latency when updating large numbers of simple rows. .. versionadded:: 1.0.0 .. warning:: The bulk update feature allows for a lower-latency UPDATE of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw UPDATES of records. **Please read the list of caveats at** :ref:`bulk_operations_caveats` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param mapper: a mapped class, or the actual :class:`_orm.Mapper` object, representing the single kind of object represented within the mapping list. :param mappings: a sequence of dictionaries, each one containing the state of the mapped row to be updated, in terms of the attribute names on the mapped class. If the mapping refers to multiple tables, such as a joined-inheritance mapping, each dictionary may contain keys corresponding to all tables. All those keys which are present and are not part of the primary key are applied to the SET clause of the UPDATE statement; the primary key values, which are required, are applied to the WHERE clause. .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_insert_mappings` :meth:`.Session.bulk_save_objects` TFNr���)rM���r��r���s��� r"���r����zSession.bulk_update_mappingsJ��s6������b� � � ��H�d�E�5�%�� �� �� �� �� r*���c����������������������t����������|������������}d|�_��������|����������������������d�������������} �|rt����������j��������|||||�������������nt����������j��������||||||�������������|������������������������������������nH#��t����������j����������������������5��|� ��������������������d��������������d�d�d��������������n#�1�swxY�w�Y���Y�nxY�wd|�_��������d�S�#�d|�_��������w�xY�w)NTr���r���F) r���rv���r����r����_bulk_update�_bulk_insertr����r���r����r����) rM���r��r���r����isstatesr���r���r���r����s ��� r"���r���zSession._bulk_save_mappings��sG������"�&�)�)������j�j��j�6�6�� #��� ��(�����'����������(�����#� � ������ ��� � � � �� >��"�$�$�� >�� >��$�$��$�=�=�=� >�� >�� >�� >�� >�� >�� >�� >�� >�� >�� >����� >�� >�� >�� >�������#�D�N�N�N��U�D�N�"�"�"�"sB����AA7��6C��7B<�B/�#B<�/B3 �3B<�6B3 �7B<�:C�� C)z0.8z�The :paramref:`.Session.is_modified.passive` flag is deprecated and will be removed in a future release. The flag is no longer used and is ignored.r���c������������������ ����t����������|������������}|j��������sdS�|j��������}|j��������j��������D�]a}|st����������|j��������d������������st����������|j��������d������������s�/|j�����������������������������||t����������j���������������������\��}}} |s| r�dS��bdS�)aZ ��Return ``True`` if the given instance has locally modified attributes. This method retrieves the history for each instrumented attribute on the instance and performs a comparison of the current value to its previously committed value, if any. It is in effect a more expensive and accurate version of checking for the given instance in the :attr:`.Session.dirty` collection; a full test for each attribute's net "dirty" status is performed. E.g.:: return session.is_modified(someobject) A few caveats to this method apply: * Instances present in the :attr:`.Session.dirty` collection may report ``False`` when tested with this method. This is because the object may have received change events via attribute mutation, thus placing it in :attr:`.Session.dirty`, but ultimately the state is the same as that loaded from the database, resulting in no net change here. * Scalar attributes may not have recorded the previously set value when a new value was applied, if the attribute was not loaded, or was expired, at the time the new value was received - in these cases, the attribute is assumed to have a change, even if there is ultimately no net change against its database value. SQLAlchemy in most cases does not need the "old" value when a set event occurs, so it skips the expense of a SQL call if the old value isn't present, based on the assumption that an UPDATE of the scalar value is usually needed, and in those few cases where it isn't, is less expensive on average than issuing a defensive SELECT. The "old" value is fetched unconditionally upon set only if the attribute container has the ``active_history`` flag set to ``True``. This flag is set typically for primary key attributes and scalar object references that are not a simple many-to-one. To set this flag for any arbitrary mapped column, use the ``active_history`` argument with :func:`.column_property`. :param instance: mapped instance to be tested for pending changes. :param include_collections: Indicates if multivalued collections should be included in the operation. Setting this to ``False`` is a way to detect only local-column based properties (i.e. scalar columns or many-to-one foreign keys) that would result in an UPDATE for this instance upon flush. :param passive: not used F�get_collection�get_historyr���T) r���r����r����rX��r����hasattr�implr��� NO_CHANGE) rM���r2����include_collectionsr���r����dict_�attr�added� unchangedr���s ��� r"���r����zSession.is_modified���s�������x��X�&�&���~�� ��5�� ���M�,�� �� �D�'� ��D�I�'7�8�8� ���T�Y� �6�6� ���*.�)�*?�*?��u�j�&:��+@��+��+�'�U�I�w���� ��� ��t�t� ���5r*���c������������������(�����|�j���������o|�j���������j��������S�)a2��True if this :class:`.Session` is in "transaction mode" and is not in "partial rollback" state. The :class:`.Session` in its default mode of ``autocommit=False`` is essentially always in "transaction mode", in that a :class:`.SessionTransaction` is associated with it as soon as it is instantiated. This :class:`.SessionTransaction` is immediately replaced with a new one as soon as it is ended, due to a rollback, commit, or close operation. "Transaction mode" does *not* indicate whether or not actual database connection resources are in use; the :class:`.SessionTransaction` object coordinates among zero or more actual database transactions, and starts out with none, accumulating individual DBAPI connections as different data sources are used within its scope. The best way to track when a particular :class:`.Session` has actually begun to use DBAPI resources is to implement a listener using the :meth:`.SessionEvents.after_begin` method, which will deliver both the :class:`.Session` as well as the target :class:`_engine.Connection` to a user-defined event listener. The "partial rollback" state refers to when an "inner" transaction, typically used during a flush, encounters an error and emits a rollback of the DBAPI connection. At this point, the :class:`.Session` is in "partial rollback" and awaits for the user to call :meth:`.Session.rollback`, in order to close out the transaction stack. It is in this "partial rollback" period that the :attr:`.is_active` flag returns False. After the call to :meth:`.Session.rollback`, the :class:`.SessionTransaction` is replaced with a new one and :attr:`.is_active` returns ``True`` again. When a :class:`.Session` is used in ``autocommit=True`` mode, the :class:`.SessionTransaction` is only instantiated within the scope of a flush call, or when :meth:`.Session.begin` is called. So :attr:`.is_active` will always be ``False`` outside of a flush or :meth:`.Session.begin` block in this mode, and will be ``True`` within the :meth:`.Session.begin` block as long as it doesn't enter "partial rollback" state. From all the above, it follows that the only purpose to this flag is for application frameworks that wish to detect if a "rollback" is necessary within a generic error handling routine, for :class:`.Session` objects that would otherwise be in "partial rollback" mode. In a typical integration case, this is also not necessary as it is standard practice to emit :meth:`.Session.rollback` unconditionally within the outermost exception catch. To track the transactional state of a :class:`.Session` fully, use event listeners, primarily the :meth:`.SessionEvents.after_begin`, :meth:`.SessionEvents.after_commit`, :meth:`.SessionEvents.after_rollback` and related events. )r����rT���rQ���s��� r"���rT���zSession.is_active���s������p���>�D�$4�$>�>r*���c������������������4�����|�j��������������������������������������������S�)z�The set of all persistent states considered dirty. This method returns all states that were modified including those that were possibly deleted. )r����r���rQ���s��� r"���r���zSession._dirty_statesB��s�������� �.�.�0�0�0r*���c������������������N�������t����������j����������fd���j��������D���������������������������S�)aZ��The set of all persistent instances considered dirty. E.g.:: some_mapped_object in session.dirty Instances are considered dirty when they were modified but not deleted. Note that this 'dirty' calculation is 'optimistic'; most attribute-setting or collection modification operations will mark an instance as 'dirty' and place it in this set, even if there is no net change to the attribute's value. At flush time, the value of each attribute is compared to its previously saved value, and if there's no net change, no SQL operation will occur (this is a more expensive operation so it's only done at flush time). To check if an instance has actionable net changes to its attributes, use the :meth:`.Session.is_modified` method. c������������������J������g�|�]}|�j���������v�|������������������������������������� S�r:���)rs���rr��)rg��r���rM���s��� �r"���rh��z!Session.dirty.<locals>.<listcomp>e��s8�������� �� �� ���� �-�-��� � ���-�-�-r*���)r����IdentitySetr���rQ���s���`r"���r���z Session.dirtyL��sC�������0��� �� �� �� �!�/� �� �� � �� �� r*���c������������������r�����t����������j��������t����������|�j�������������������������������������������������������������������S�)zDThe set of all instances marked as 'deleted' within this ``Session``)r���r��r����rs���r����rQ���s��� r"���r���zSession.deletedl��s+����������T�]�%9�%9�%;�%;� <� <�=�=�=r*���c������������������r�����t����������j��������t����������|�j�������������������������������������������������������������������S�)zAThe set of all instances marked as 'new' within this ``Session``.)r���r��r����rr���r����rQ���s��� r"���r���zSession.newr��s+����������T�Y�%5�%5�%7�%7� 8� 8�9�9�9r*���)NTTTFFNNNTNN)FF)NNNFNrS���)NNN)NNr����)T)TNN)FTTr����)Nr3���r4���r5���r6����public_methodsr����deprecated_paramsrO����connection_callabler�����memoized_propertyr����r����r����r����r����r����rh���rd���r����r����r����r����r��r����r����r*��r-��rc���r ���r�����contextmanagerr>��rC��r����r����r����rK��rZ��r8���rd��r����r����r}��ry��r���r����r����r���r����r���r����r���rV��r���r����r���r���r���r���r����r����r���rw���r���r����r���r����r����r����r���r����rT���r����r���r���r���r���r:���r*���r"���r���r���k��s������������������N�:��T�� �( � �!�����4����'+������!� ��I(��I(��I(�1���0I(�V����K�F� ���������> ��> ��> ��> �@'��'��'�2(��(��(�(""��""��""�H#��#��#�*��� ��� O ��O ��O ��O �b �� �� �� �J ��J ��J ��J �X������� +�� +�� +� *�� *�� *�D.��.��.� @�� @�� @������2%��%��%�8$��$��$�8A ��A ��A ��A �F9��9��9��� ��'��'������X�'�4A��A��A�&����]��]��]��]�~!C��!C��!C�F,3��,3��,3��,3�\.��.��.� �� �� ���T�_� � '����)��)� ���)�N��N��N�0 �� �� �� �P!��P!��P!�d:��:��:�3��3��3�(*��*��*��*�.,��,��,�+��+��+�6��6��6�& 1�� 1�� 1�DM'��M'��M'��M'�f���"� S��S��S��S�j����� +�� +�� +�$=��$=��$=��$=�L%��%��%�;+��;+��;+�z �� �� � <�� <�� <�+��+��+� �� �� �M��M��M�$#��$#��$#��$#�L �� �� � �� �� �{>��{>��{>��{>�@�� ��g��g��g��g�T�EJ�c ��c ��c ��c �J3 ��3 ��3 �j&#��&#��&#�P��T�� ������I��I��I����I�V��7?��7?���X�7?�r��L����1��1���X�1��� �� ���X� �>��>��>���X�>� ��:��:���X�:��:��:r*���r���c��������������������8�����e�Zd�ZdZdeddddfd�Zd��Zd��Zd��ZdS�) r���a3��A configurable :class:`.Session` factory. The :class:`.sessionmaker` factory generates new :class:`.Session` objects when called, creating them given the configurational arguments established here. e.g.:: # global scope Session = sessionmaker(autoflush=False) # later, in a local scope, create and use a session: sess = Session() Any keyword arguments sent to the constructor itself will override the "configured" keywords:: Session = sessionmaker() # bind an individual session to a connection sess = Session(bind=connection) The class also includes a method :meth:`.configure`, which can be used to specify additional keyword arguments to the factory, which will take effect for subsequent :class:`.Session` objects generated. This is usually used to associate one or more :class:`_engine.Engine` objects with an existing :class:`.sessionmaker` factory before it is first used:: # application starts Session = sessionmaker() # ... later engine = create_engine('sqlite:///foo.db') Session.configure(bind=engine) sess = Session() .. seealso:: :ref:`session_getting` - introductory text on creating sessions using :class:`.sessionmaker`. NTFc�����������������������||d<���||d<���||d<���||d<���|�||d<���||�_���������t����������|j��������|fi�������������|�_��������dS�)al��Construct a new :class:`.sessionmaker`. All arguments here except for ``class_`` correspond to arguments accepted by :class:`.Session` directly. See the :meth:`.Session.__init__` docstring for more details on parameters. :param bind: a :class:`_engine.Engine` or other :class:`.Connectable` with which newly created :class:`.Session` objects will be associated. :param class\_: class to use in order to create new :class:`.Session` objects. Defaults to :class:`.Session`. :param autoflush: The autoflush setting to use with newly created :class:`.Session` objects. :param autocommit: The autocommit setting to use with newly created :class:`.Session` objects. :param expire_on_commit=True: the :paramref:`_orm.Session.expire_on_commit` setting to use with newly created :class:`.Session` objects. :param info: optional dictionary of information that will be available via :attr:`.Session.info`. Note this dictionary is *updated*, not replaced, when the ``info`` parameter is specified to the specific :class:`.Session` construction operation. .. versionadded:: 0.9.0 :param \**kw: all other keyword arguments are passed to the constructor of newly created :class:`.Session` objects. rg���r����r����r����Nr����)r��r$��r3���r ��)rM���rg���r ��r����r����r����r����r��s��� r"���rO���zsessionmaker.__init__���s_������P���6� �#��;��%��<��!1�������B�v�J������6�?�V�I�r�:�:����r*���c����������������������|�j��������������������������������������������D�]Z\��}}|dk����r9d|v�r5|�����������������������������������}|���������������������|d����������������������||d<����D|���������������������||��������������[�|�j��������di�|��S�)ae��Produce a new :class:`.Session` object using the configuration established in this :class:`.sessionmaker`. In Python, the ``__call__`` method is invoked on an object when it is "called" in the same way as a function:: Session = sessionmaker() session = Session() # invokes sessionmaker.__call__() r����r:���)r��r�����copyr����� setdefaultr ��)rM����local_kw�k�v�ds��� r"����__call__zsessionmaker.__call__���s���������G�M�M�O�O�� *�� *�D�A�q��F�{�{�v��1�1��F�F�H�H������&�)�*�*�*�#$��� � ��#�#�A�q�)�)�)�)��t�{�&�&�X�&�&�&r*���c������������������:�����|�j������������������������������|�������������dS�)z�(Re)configure the arguments for this sessionmaker. e.g.:: Session = sessionmaker() Session.configure(bind=create_engine('sqlite://')) N)r��r����)rM����new_kws��� r"���� configurezsessionmaker.configure���s������� ����v�����r*���c����������� ������������|�j���������j���������d|�j��������j���������dd���������������������d��|�j�������������������������������������������D����������������������������d�S�)Nz(class_=r0��c��������������3����*���K����|�]\��}}|�d�|��V����dS�)�=Nr:���)rg��r!��r"��s��� r"���rp��z(sessionmaker.__repr__.<locals>.<genexpr>���s1����������C�C�4�1�a����A�A�&�C�C�C�C�C�Cr*����))� __class__r3���r ��r9��r��r����rQ���s��� r"����__repr__zsessionmaker.__repr__���sV�������N�#�#�#��K� � � ��I�I�C�C�4�7�=�=�?�?�C�C�C�C�C�C�C� �� r*���) r3���r4���r5���r6���r���rO���r$��r'��r-��r:���r*���r"���r���r���y��su��������������,��,�`������ �1;��1;��1;��1;�f'��'��'�( �� �� � �� �� �� �� r*���r���c�������������������f�����t����������������������������������������������D�]}�|��������������������������������������dS�)aO��Close all sessions in memory. This function consults a global registry of all :class:`.Session` objects and calls :meth:`.Session.close` on them, which resets them to a clean state. This function is not for general use but may be useful for test suites within the teardown scheme. .. versionadded:: 1.3 N)r ���r����r����)r����s��� r"���r'���r'��� ��s8�������� � �"�"������� � �������r*���c������������������������t����������j��������|�������������}t����������|������������}|r|���������������������|g�������������|j��������������������������������������������|j��������r|`|j��������r|`|j��������r|`dS�dS�)aM��Alter the state of the given instance so that it is :term:`transient`. .. note:: :func:`.make_transient` is a special-case function for advanced use cases only. The given mapped instance is assumed to be in the :term:`persistent` or :term:`detached` state. The function will remove its association with any :class:`.Session` as well as its :attr:`.InstanceState.identity`. The effect is that the object will behave as though it were newly constructed, except retaining any attribute / collection values that were loaded at the time of the call. The :attr:`.InstanceState.deleted` flag is also reset if this object had been deleted as a result of using :meth:`.Session.delete`. .. warning:: :func:`.make_transient` does **not** "unexpire" or otherwise eagerly load ORM-mapped attributes that are not currently loaded at the time the function is called. This includes attributes which: * were expired via :meth:`.Session.expire` * were expired as the natural effect of committing a session transaction, e.g. :meth:`.Session.commit` * are normally :term:`lazy loaded` but are not currently loaded * are "deferred" via :ref:`deferred` and are not yet loaded * were not present in the query which loaded this object, such as that which is common in joined table inheritance and other scenarios. After :func:`.make_transient` is called, unloaded attributes such as those above will normally resolve to the value ``None`` when accessed, or an empty collection for a collection-oriented attribute. As the object is transient and un-associated with any database identity, it will no longer retrieve these values. .. seealso:: :func:`.make_transient_to_detached` N) r���rH��r#���r�����expired_attributesr����� callablesr����rs���)r2���r���r����s��� r"����make_transientr2�� ��s�������\� �%�h�/�/�E��u���A���#� ���5�'�"�"�"�� ��"�"�$�$�$�� �����O��y����I��~����N�N�N���r*���c������������������6����t����������j��������|�������������}|j��������s|j��������rt ����������j��������d�������������|j�����������������������������|������������|_��������|j��������r|`|� ��������������������|j ���������������������|���������������������|j ��������|j���������������������dS�)a���Make the given transient instance :term:`detached`. .. note:: :func:`.make_transient_to_detached` is a special-case function for advanced use cases only. All attribute history on the given instance will be reset as though the instance were freshly loaded from a query. Missing attributes will be marked as expired. The primary key attributes of the object, which are required, will be made into the "key" of the instance. The object can then be added to a session, or merged possibly with the load=False flag, at which point it will look as if it were loaded that way, without emitting SQL. This is a special use case function that differs from a normal call to :meth:`.Session.merge` in that a given persistent state can be manufactured without any SQL calls. .. versionadded:: 0.9.5 .. seealso:: :func:`.make_transient` :meth:`.Session.enable_relationship_loading` zGiven object must be transientN) r���rH��r���r����rG���rH���r��rs��rs���r���r����rW���unloaded_expirable)r2���r���s��� r"����make_transient_to_detachedr5��T ��s�������>� �%�h�/�/�E����K�5�9��K��(�)I�J�J�J���5�5�e�<�<�E�I��~����N� ���e�j�!�!�!� ���U�Z��)A�B�B�B�B�Br*���c������������������������ �t����������j��������|�������������}t����������|������������S�#�t����������j��������$�r3}t����������j��������t����������j��������|�������������|��������������Y�d}~dS�d}~ww�xY�w)z�Return the :class:`.Session` to which the given instance belongs. This is essentially the same as the :attr:`.InstanceState.session` accessor. See that attribute for details. r��N)r���rH��r#���r���rI��r���r����rJ��)r2���r���r'��s��� r"���r1���r1���} ��s�������%��)�(�3�3����e�$�$�$�� ��<�� �� �� ����%�h�/�/�� �� �� �� �� �� �� �� �� �� ����� ���s����%��A'�(A"�"A')6r6���r���r����rx�����r���r���r���r���r���r ���r���r�����baser���r ���r���r���r���r���r����deprecated_interfacesr���� unitofworkr���r���rG���r���r���� inspectionr���r���r5���__all__�WeakValueDictionaryr ���r#����objectr%����symbolr;���r<���r=���r>���r?���r���r���r���r'���r2��r5��r1����counterr����r:���r*���r"����<module>rA�����sm�����8��7���������� � � � �������������������������������������������������������������������������������������������"��"��"��"��"��"��������������������������������������������������������������������������3��3��3��3��3��3��&��&��&��&��&��&�������������������������������������������������� �� �� �� �� �� ��������������"��"��"��"��"��"��P� O� O��'�G�'�)�)� ��?� �� �� �!(��!(��!(��!(��!(�6��!(��!(��!(�H� ���X� � ���4�;�z�"�"���D�K��$�$� ��4�;�z�"�"�� ���X� � ��C��C��C��C��C���C��C��C�LK(:��K(:��K(:��K(:��K(:�"��K(:��K(:��K(:�\PF ��F ��F ��F ��F �'��F ��F ��F �R�����$=��=��=�@&C��&C��&C�R%��%��%�&��������r*���