HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/__pycache__/strategies.cpython-310.pyc
o

���g:��@s�dZddlmZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZd
dlm
Z
d
dlmZd
d
lmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlm Z d
dl!m"Z"d
dl!m#Z#d
dl!m$Z$d
dl!m%Z%d
d lm&Z&d
d!lm'Z'd
d"l(m)Z)d
d#l*m+Z+d
d$l,m-Z-d
d%lm.Z.d
d&lm/Z/d'd(lm0Z0d'dlmZ1d'd)lm2Z2d'd*lm3Z3d'd+lm4Z4d'dlmZd'dl4mZ5d'd,l4m6Z6d'd-l7m8Z8d'd.l7m9Z9d'd/l:m;Z;e
�r3d
d0l<m=Z=d
d1lm>Z>d'd2l?m@Z@					3	dfd4d5�ZAejBjCd3d3d6�Gd7d8�d8e&��ZDe3jEejBjCd9d3d6�Gd:d;�d;e&���ZFe3jEejBjCd9d<�Gd=d>�d>eF���ZGe3jEejBjCd9d9d?�ejBjCd9d9d9d@�ejBjCd9dA�GdBdC�dCe&�����ZHGdDdE�dE�ZIGdFdG�dGe&�ZJe3jEej>jCd9dA�GdHdI�dIe&���ZKe3jEej>jCdJdK�ej>jCddK�GdLdM�dMeJ����ZLe3jEej>jCd9dK�ej>jCdNdK�ej>jCdOdK�ej>jCdPdK�ej>jCdQdK�GdRdS�dSeJejMe3jN�������ZOGdTdU�dU�ZPGdVdW�dWeJ�ZQej>jCdXdK�GdYdZ�dZeQ��ZRe3jEej>jCd[dK�Gd\d]�d]eQ���ZSe3jEej>jCd^dK�ej>jCd3dK�Gd_d`�d`eJ����ZTe3jEej>jCdadK�Gdbdc�dceQejM���ZUddde�ZVdS)gzWsqlalchemy.orm.interfaces.LoaderStrategy
   implementations, and related MapperOptions.�)�annotationsN)�Any)�Dict)�Optional)�Tuple)�
TYPE_CHECKING)�Union�)�
attributes)�exc)�
interfaces)�loading)�
path_registry)�
properties)�query)�
relationships)�
unitofwork)�util)�_DEFER_FOR_STATE)�_RAISE_FOR_STATE)�_SET_DEFERRED_EXPIRED)�ATTR_WAS_SET)�LoaderCallableStatus)�PASSIVE_OFF)�PassiveFlag)�_column_descriptions)�ORMCompileState)�ORMSelectCompileState)�QueryContext)�LoaderStrategy)�StrategizedProperty)�_state_session)�
InstanceState)�Load)�_none_only_set)�AliasedClass�)�event)�inspect)�log)�sql)�visitors)�LABEL_STYLE_TABLENAME_PLUS_COL)�Select)�Literal)�Mapper)�RelationshipProperty)�
ColumnElementFc	s g}
|o|j�|r|jr|
�t�|j|jjvr+|jj|j\��|
���fdd��|r3|
�tj�|rG|j	��rG|j
rG|
���fdd��|jD]C}||j�
|j�ur�|j�|j�s�tj|j|jf|�|||oq|jpq|jtju|||||p{|j|jd�|	��}|
D]}
|
||�q�qJdS)Ncstj||j�fi���S�N)�orm_util�_validator_events�key��desc�prop)�fn�opts��D/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/strategies.py�<lambda>\s
��z%_register_attribute.<locals>.<lambda>cst�|���Sr2)r
�backref_listenersr6)�backref�uselistr;r<r=js�)�parent_tokenr@�compare_function�	useobject�trackparent�typecallable�	callable_�active_history�
impl_class�send_modified_events�doc)r@�
single_parent�append�single_parent_validatorr5�parent�
validatorsr�track_cascade_events�back_populates�_effective_sync_backref�self_and_descendants�_props�get�
class_manager�_attr_has_implr
�register_attribute_impl�class_�	directionr�	ONETOMANY�viewonlyrJ)r8�mapperrCrBrErF�proxy_propertyrGrH�kw�listen_hooks�mr7�hookr;)r?r9r:r@r<�_register_attributeFs^


�
�
���
����rc)�
instrument�deferredcs8eZdZdZdZ�fdd�Z	d
dd�Zdd	�Z�ZS)�UninstrumentedColumnLoaderz�Represent a non-instrumented MapperProperty.

    The polymorphic_on argument of mapper() often results in this,
    if the argument is against the with_polymorphic selectable.

    ��columnsc�t��||�|jj|_dSr2)�super�__init__�parent_propertyrh��selfrN�strategy_key��	__class__r;r<rk��z#UninstrumentedColumnLoader.__init__Nc	Ks*|jD]}|r|j|}|�||�qdSr2)rh�_append_dedupe_col_collection)	rn�
compile_state�query_entity�path�loadopt�adapter�column_collection�kwargs�cr;r;r<�setup_query�s



�z&UninstrumentedColumnLoader.setup_queryc		CsdSr2r;�	rn�contextrurvrwr]�resultrx�
populatorsr;r;r<�create_row_processor�sz/UninstrumentedColumnLoader.create_row_processorr2)	�__name__�
__module__�__qualname__�__doc__�	__slots__rkr|r��
__classcell__r;r;rpr<rf�s
�rfTcs@eZdZdZdZ�fdd�Z	ddd�Zdd	�Zd
d�Z�Z	S)
�ColumnLoaderz8Provide loading behavior for a :class:`.ColumnProperty`.)rh�is_compositecs*t��||�|jj|_t|jd�|_dS)N�composite_class)rjrkrlrh�hasattrr�rmrpr;r<rk�s
zColumnLoader.__init__Fc	Ksv|jD]}
|r|r|�|
�}
|
durdSn|j|
}
|�|
|�q|jd}|r4|j|}|dur4dS|||j<dS�Nr)rh�adapt_check_presentrsrl)rnrtrurvrwrxry�memoized_populators�check_for_adaptrzr{�fetchr;r;r<r|�s

�


zColumnLoader.setup_querycCs`d|_|jdj}|jjp"|jdjp"|jduo"|j�|jd�|ju}t	|j|d|j
|d�dS)NTrF)rCrBrG)�is_class_levelrh�typerlrG�primary_key�version_id_col�_columntopropertyrUrc�compare_values)rnr]�coltyperGr;r;r<�init_class_attribute�s"
�
��

�z!ColumnLoader.init_class_attributec	Cs\|jD]}	|r|j|	}	|�|	d�}
|
r!|d�|j|
f�dSq|d�|jdf�dS�NF�quick�expireT)rh�_getterrLr5)rnr~rurvrwr]rrxr��col�getterr;r;r<r�s

�z!ColumnLoader.create_row_processor�F)
r�r�r�r�r�rkr|r�r�r�r;r;rpr<r��s
�!r�)�query_expressioncs4eZdZ�fdd�Zdd�Zdd�Zdd�Z�ZS)	�ExpressionColumnLoadercs<t��||�t���d��t�fdd�|jjD��|_dS)Nc3s�|]	}|���VqdSr2)�compare��.0r{��nullr;r<�	<genexpr>)s�
�z2ExpressionColumnLoader.__init__.<locals>.<genexpr>)	rjrkr*r��label�anyrlrh�_have_default_expressionrmrpr�r<rk"s
�zExpressionColumnLoader.__init__cKs�d}	|r|jr|j}	n|jr|jj}	|	durdS|	D]}
|r#|j|
}
|�|
|�q|	d}|r;|j|}|dur;dS|||j<dSr�)�_extra_criteriar�rlrhrs)rnrtrurvrwrxryr�rzrhr{r�r;r;r<r|-s"


z"ExpressionColumnLoader.setup_queryc	Csr|r5|jr7|j}	|	D]}
|r|j|
}
|�|
d�}|r(|d�|j|f�dSq
|d�|jdf�dSdSdSr�)r�rhr�rLr5)rnr~rurvrwr]rrxr�rhr�r�r;r;r<r�Rs


��z+ExpressionColumnLoader.create_row_processorcCs(d|_t|j|d|jdjjdd�dS)NTFr)rCrB�accepts_scalar_loader)r�rcrlrhr�r��rnr]r;r;r<r�ls
�z+ExpressionColumnLoader.init_class_attribute)r�r�r�rkr|r�r�r�r;r;rpr<r�s
%r�)rerd)rerd�	raiseload)�
do_nothingcsPeZdZdZdZ�fdd�Zdd�Zdd�Z		dd
d�Zdd
�Z	dd�Z
�ZS)�DeferredColumnLoaderzAProvide loading behavior for a deferred :class:`.ColumnProperty`.)rh�groupr�csJt��||�t|jd�rtd��|j�dd�|_|jj|_|jj	|_	dS)Nr�z8Deferred loading for composite types not implemented yetr�F)
rjrkr�rl�NotImplementedError�
strategy_optsrUr�rhr�rmrpr;r<rk�s�
zDeferredColumnLoader.__init__c	

Cs�|jr"|jjjr"|j|jjjvr"|j�d��||||||||�dS|js=|j	r-|jj
}	n|jj}	|d�|j|	f�dS|d�|jdf�dS)N�)reF�rdT�newr�F)
�
refresh_stater�_compile_options�_only_load_propsr5rl�
_get_strategyr�r�r��_raise_column_loader�_deferred_column_loaderrL)
rnr~rurvrwr]rrxr��set_deferred_for_local_stater;r;r<r��s4������z)DeferredColumnLoader.create_row_processorcCs,d|_t|j|d|jdjj|jdd�dS)NTFr)rCrBrF�load_on_unexpire)r�rcrlrhr�r��_load_for_stater�r;r;r<r��s
�z)DeferredColumnLoader.init_class_attributeNc	
Ks�|jjr|jjs*|rt|j��|jj�s*|r#|j	r#|j
�d|j	d�s*|r?|j|vr?|j�
d�j|||||||fi|	��dS|jrIt||j<dS|jsSt||j<dSt||j<dS)Nzundefer_group_%sFr�)�compile_options�_render_for_subqueryrl�_renders_in_subqueries�setrh�intersectionrN�_should_undefer_in_wildcardr��
local_optsrUr5r�r|r�rr�rr)
rnrtrurvrwrxryr��only_load_propsr_r;r;r<r|�sP���
���
�
���
��

�z DeferredColumnLoader.setup_querycs��jstjS|tj@stjS�jj}�jr �fdd�|j	D�}n�jg}�fdd�|D�}t
��}|durBt�dt
����jf���jrL���|d�t��j�t|�t�tjS)Ncs4g|]}t|t�rt|jt�r|j�jkr|j�qSr;)�
isinstancer �strategyr�r�r5)r��p�rnr;r<�
<listcomp>	s�
��z8DeferredColumnLoader._load_for_state.<locals>.<listcomp>csg|]	}|�jvr|�qSr;)�
unmodified)r��k)�stater;r<r�szfParent instance %s is not bound to a Session; deferred load operation of attribute '%s' cannot proceed�raise)r5r�
ATTR_EMPTYr�SQL_OK�PASSIVE_NO_RESULT�managerr]r��iterate_propertiesr!�orm_exc�DetachedInstanceErrorr3�	state_strr��_invoke_raise_loadr
�load_scalar_attributesr�rr)rnr��passive�localparent�toloadr��sessionr;)rnr�r<r��s0

����z$DeferredColumnLoader._load_for_statecCst�d|f��)Nz+'%s' is not available due to raiseload=True��sa_exc�InvalidRequestError�rnr�r��lazyr;r;r<r�'s�z'DeferredColumnLoader._invoke_raise_loadr2)r�r�r�r�r�rkr�r�r|r�r�r�r;r;rpr<r�xs
3
�3(r�c@s*eZdZdZdd
dd�Zejfd	d
�ZdS)�LoadDeferredColumnsz7serializable loader object used by DeferredColumnLoaderFr5�strr��boolcCs||_||_dSr2)r5r�)rnr5r�r;r;r<rk0s
zLoadDeferredColumns.__init__cCs>|j}|jj}|j|}|jrd}nd}|�|�}|�||�S)N)�reTr�)r�T)r�r�)r5r�r]rTr�r�r�)rnr�r�r5r�r8ror�r;r;r<�__call__4s

zLoadDeferredColumns.__call__Nr�)r5r�r�r�)r�r�r�r�rkr
rr�r;r;r;r<r�-sr�cs,eZdZdZdZ�fdd�Zdd�Z�ZS)�AbstractRelationshipLoaderz0LoaderStratgies which deal with related objects.)r]�targetr@�entitycs:t��||�|jj|_|jj|_|jj|_|jj|_dSr2)rjrkrlr]r�r�r@rmrpr;r<rkJs



z#AbstractRelationshipLoader.__init__c		
Cs |j�d��||||||||�S)N))r��	immediate)rlr�r�r}r;r;r<�#_immediateload_create_row_processorQs���z>AbstractRelationshipLoader._immediateload_create_row_processor)r�r�r�r�r�rkr�r�r;r;rpr<r�Es
r�c@seZdZdZdS)�DoNothingLoaderz�Relationship loader that makes no change to the object's state.

    Compared to NoLoader, this loader does not initialize the
    collection/attribute to empty/none; the usual default LazyLoader will
    take effect.

    N)r�r�r�r�r;r;r;r<r�jsr��noload)r�c@s$eZdZdZdZdd�Zdd�ZdS)�NoLoaderzQProvide loading behavior for a :class:`.Relationship`
    with "lazy=None".

    r;cCs d|_t|j|d|jjd�dS)NT)rCrE)r�rcrl�collection_classr�r;r;r<r��s
�zNoLoader.init_class_attributec	
s$�fdd�}	|d��j|	f�dS)Ncs(�jr
t�||�j�dSd|�j<dSr2)r@r
�init_state_collectionr5�r��dict_�rowr�r;r<�invoke_no_load�sz5NoLoader.create_row_processor.<locals>.invoke_no_loadr�)rLr5)
rnr~rurvrwr]rrxr�r�r;r�r<r��szNoLoader.create_row_processorN)r�r�r�r�r�r�r�r;r;r;r<r�vs

r��selectr��raise_on_sql�baked_selectcs�eZdZUdZdZded<ded<ded<ded<d	ed
<d#�fdd�Zdd�Zdd�Zdd�Z	dd�Z
ddddejfdd�Z
dd�Ze�d�dd ��Zd!d"�Z�ZS)$�
LazyLoaderztProvide loading behavior for a :class:`.Relationship`
    with "lazy=True", that is loads when first accessed.

    )
�
_lazywhere�_rev_lazywhere�_lazyload_reverse_option�	_order_by�use_get�is_aliased_class�_bind_to_col�_equated_columns�_rev_bind_to_col�_rev_equated_columns�_simple_lazy_clause�
_raise_always�
_raise_on_sqlzColumnElement[bool]r�zDict[str, ColumnElement[Any]]rr�r�RelationshipProperty[Any]rlrNro�Tuple[Any, ...]cs8t��||�|jddk|_|jddk|_t|j�j|_|jj	}|�
�\|_|_|_
|j
dd�\|_|_|_|jjrJdd�t�|jj�D�|_nd|_|j�d||j�|jom|jom|jjd	j|jdd
|jjd�|_|jr�t|j
�D]}||jjvr�|jj|D]
}|j
||j
|<q�qw|j�d|�dSdS)
Nr�r�r�T)�reverse_directioncSsg|]
}t�|ddi��qS)�
_orm_adaptT)�sql_util�_deep_annotate�r��elemr;r;r<r��s��z'LazyLoader.__init__.<locals>.<listcomp>z%s lazy loading clause %srF��use_proxies�compare_keys�equivalentsz4%s will use Session.get() to optimize instance loads)rjrkr�rrr(r�rrl�_join_condition�create_lazy_clauser�rrr�rr�order_byr�to_listr��logger�infor@�_get_clauser�r]�_equivalent_columnsr��list)rnrNro�join_conditionr�r{rpr;r<rk�sR�
�
�
������zLazyLoader.__init__c	Csvd|_|jj}|jjrd}d}n|jjtjus|js&|r!d}d}n	d}d}nd}}t|j|d|j	|jj
||d�dS)NTF)rCrFrErG�_deferred_history)r�rl�_legacy_inactive_history_stylerGrZr�	MANYTOONEr�rcr�r�)rnr]rrGrr;r;r<r�s0��
�zLazyLoader.init_class_attributecsdt�|jddi�}||j}�g�dd�}t�|id|i���fdd�}t�|id|i�}|�fS)NrTcSs
d|_dS)NF)�unique��	bindparamr;r;r<�visit_bindparam+s
zFLazyLoader._memoized_attr__simple_lazy_clause.<locals>.visit_bindparamr#csL|j�vr��|j�|jdf�dS|jdur$��|jd|jf�dSdSr2)�_identifying_keyrLr5�callable�valuer"��bind_to_col�paramsr;r<r$0s
��
�)rr
r�rr+�traverse�cloned_traverse)rn�	lazywhere�	criterionr$r;r(r<�"_memoized_attr__simple_lazy_clause"s
�
�z-LazyLoader._memoized_attr__simple_lazy_clausecCs�|j\}}|durt�|dd�|D��S|jj}|��}t�|�}|tj	@r+|tj	N}i}|D]%\}	}
}|
durP|rH|tj
@rH|�|||
|�}n|�|||
|�}|||	<q/||fS)NcSsg|]\}}}|�qSr;r;)r�r5�identr'r;r;r<r�G�z4LazyLoader._generate_lazy_clause.<locals>.<listcomp>)
rr�adapt_criterion_to_nullrlrN�objr
�
instance_dictr�INIT_OK�LOAD_AGAINST_COMMITTED�#_get_committed_state_attr_by_column�_get_state_attr_by_column)rnr�r�r.�
param_keysr]�or�r*r5r0r'r;r;r<�_generate_lazy_clauseBs,
�


��
z LazyLoader._generate_lazy_clausecCst�d||f��)Nz&'%s' is not available due to lazy='%s'r�r�r;r;r<r�bs
�zLazyLoader._invoke_raise_loadNr;c
Cs�|js|jjs
|jr
|jstjS|j}d}	|jo|p|j}
|t	j
@s'|
r.|tj@s1|r1tj
S|jrG|t	j@sG|
r@|t	j@rG|�||d�t|�}|sb|t	j@rUtj
St�dt�|�|jf��|
r�|�|||�}	tj
|	vrstj
Stj|	vr{tjS|jjs�t�|	�r�dSnt�|	�r�dS|j|jvr�|t	j@s�tj S|j!|j"|	||d�}|dur�|tj#ur�dS|S|t	j
@r�|t	j@s�tj
S|�$|||	||||||�	S)Nr�zbParent instance %s is not bound to a Session; lazy load operation of attribute '%s' cannot proceed)r��lazy_loaded_from)%r5rl�load_on_pending�
_load_pending�
session_idrr�r�r�rr�r
�NON_PERSISTENT_OKr�r�NO_RAISE�RELATED_OBJECT_OKr�r!r�r�r3r��_get_ident_for_use_get�	NEVER_SETr]�allow_partial_pksr$r��
issuperset�dict�DEFERRED_HISTORY_LOADr�_identity_lookupr��PASSIVE_CLASS_MISMATCH�_emit_lazyload)
rnr�r�rw�extra_criteria�
extra_options�alternate_effective_path�execution_options�pending�primary_key_identityr�r��instancer;r;r<r�gs�
���������
���


�
��
���zLazyLoader._load_for_statecsD�jj}�tj@r
|j�n|j��j������fdd��jjD�S)Ncs"g|]
}����j|�d��qS)�r��r�r��pk�r��get_attrr�rnr�r;r<r��s��z5LazyLoader._get_ident_for_use_get.<locals>.<listcomp>)r�r]rr6r7r8rGr�)rnr�r�r��instance_mapperr;rWr<rC�s
�z!LazyLoader._get_ident_for_use_getzsqlalchemy.orm.strategy_optionsc
s�tjj��j��}
tj|
g|
jtt	j
d�}tj}|d|d�7}�j
jdur.|��j�j
j�}|j}
|
s9|tj@rAt�ddi�|_�j}|jsL|rt|jrt|durW|j�j
}n|�j
}|j}|rp|jrpd}|t��j|�f7}||_n|dur�|jj�j
}n|�j
}|r�|j|7_|jd|i7_|r��jr�|t j!@s���"||d�t#j$|||||	d�S�j%r��j%|_&��fdd	�}|j'|�j
ff7_'��(||�\}}|	r�tj)�*|	d
|i�}	nd
|i}	�j|j+vr�|t j,@s�t-j.S|
r�t�/tj0|�1��r�dSnt�/tj2|�1���rdS�j�r|t j!@�s��"||d�|f|_3|j4|||	d�}|�5��6��7�}�j8�r6|St9|�}|�rN|dk�rJt�:d
�j
�|dSdS)N)�_raw_columns�_propagate_attrs�_label_styler�F)�_invoke_all_eagers�_lazy_loaded_from�	autoflush�
_current_pathr�)�load_optionsrOcsR�jjD]"}|jtjur&|jr&t|jt�s&�j	�
|jj|j
��|��|�qdSr2)rl�_reverse_propertyrZrr �_use_getr�r�r�r#�_construct_for_existing_pathr�r`rN�lazyload�process_compile_state)�compile_context�rev�rn�strategy_optionsr;r<�_lazyload_reverseBs�
�����z4LazyLoader._emit_lazyload.<locals>._lazyload_reverse�_sa_orm_load_options)rOr	zKMultiple rows returned with uselist=False for lazily-loaded attribute '%s' r);r�	preloaded�orm_strategy_optionsr��__clause_element__r-�_create_raw_selectr[r,r�default_compile_optionsr�default_load_optionsrl�	secondary�select_fromr]r5r
�NO_AUTOFLUSH�
immutabledict�_execution_optionsr�rar��	load_pathr3�LoaderCriteriaOption�
_with_options�_path_registryr�rrrAr�r
�load_on_pk_identityr��_order_by_clauses�_with_context_optionsr;�
EMPTY_DICT�
merge_withrGrHrr�has_intersection�	_none_set�values�
_never_set�_where_criteria�executer!�scalars�allr@�len�warn)rnr�r�rQr�rwrLrMrNrO�
clauseelement�stmtrarPr��effective_pathr:rk�lazy_clauser*r�lr;rir<rK�s�
��
�

�
��������
��zLazyLoader._emit_lazyloadc	
s�|j�|jjr |jjjr |j|jjjvr |�||||||||�S|jr(|rI|jrIt	�
|jt�|||jr8|�
|�nd���}	|d�|j|	f�dS|jsO|jra�fdd�}
|d�|j|
f�dSdS)Nr�cs|�|��dSr2)�_resetr��r5r;r<�reset_for_lazy_callable�s	z@LazyLoader.create_row_processor.<locals>.reset_for_lazy_callable)r5ra�_is_user_refreshrr�r�r�r�r�r"�"_instance_level_callable_processorrV�LoadLazyAttribute�_generate_extra_criteriarL�populate_existing�always_refresh)rnr~rurvrwr]rrxr��set_lazy_callabler�r;r�r<r��sF���
��
���zLazyLoader.create_row_processor)rNrror	)r�r�r�r�r��__annotations__rkr�r/r;r�rrr�rC�preload_modulerKr�r�r;r;rpr<r��s0
	<"  	
�w
r�c@s.eZdZdZdd�Zdd�Zejfdd�ZdS)	r�a�semi-serializable loader object used by LazyLoader

    Historically, this object would be carried along with instances that
    needed to run lazyloaders, so it had to be serializable to support
    cached instances.

    this is no longer a general requirement, and the case where this object
    is used is exactly the case where we can't really serialize easily,
    which is when extra criteria in the loader option is present.

    We can't reliably serialize that as it refers to mapped entities and
    AliasedClass objects that are local to the current process, which would
    need to be matched up on deserialize e.g. the sqlalchemy.ext.serializer
    approach.

    cCs||_|j|_||_||_dSr2�r5rorwrL)rnr5�initiating_strategyrwrLr;r;r<rk�s
zLoadLazyAttribute.__init__cCs(|jdur
t�d�|j|j|jdd�S)NzvCan't reliably serialize a lazyload() option that contains additional criteria; please use eager loading for this caser;r�)rLrr�r5rorwr�r;r;r<�__getstate__�s
��zLoadLazyAttribute.__getstate__cCs:|j}|jj}|j|}|j|j}|j|||j|jd�S)N)rwrL)	r5r�r]rT�_strategiesror�rwrL)rnr�r�r5rYr8r�r;r;r<r��s
�zLoadLazyAttribute.__call__N)	r�r�r�r�rkr�r
rr�r;r;r;r<r��s
r�c@seZdZdZdZddd�ZdS)�
PostLoaderz;A relationship loader that emits a second SELECT statement.r;NcCsF|jjptjj|}|��}t�d|i�}|r#|j�	dd�}|dk}	nd}d}	|dura|j
js9t�
d|j
�d���|j�	dt|���|�}|	sQ|dkrQ|d||fS|	sa|�dt|���|d	i�}tj�|||j
�rp|d||fS||j
}
||j
}|
�|jd
�s�|r�|jd|kr�|d||fSn|�|j�r�|d||fS|d||fS)
N�sa_top_level_orm_context�recursion_depth���Fz'recursion_depth option on relationship z0 not valid for non-self-referential relationship�_recursion_depth_rr	�loaderr&T)rt�current_pathr3�PathRegistry�root�_get_top_level_contextrrvr�rUrl�_is_self_referentialr�r�rO�id�unionr
�PostLoad�path_exists�containsr
�length�contains_mapperr])rnr~rvrw�
join_depthr��top_level_contextrOr��unlimited_recursion�path_w_prop�effective_path_w_propr;r;r<�_setup_for_recursionsn��
�������

���zPostLoader._setup_for_recursionr2)r�r�r�r�r�r�r;r;r;r<r�sr�r�cs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
�ImmediateLoader�r�crir2�rjrkrlr�rmrpr;r<rkWrrzImmediateLoader.__init__cC�|j�d��|�dS�N�)r�r��rlr�r�r�r;r;r<r�[��z$ImmediateLoader.init_class_attributec	Csl|jjjsdS|�||||j�\}	}
}}|
stjtjB}
ntj	tjB}
t
j�||	|j
|j|j||
||�	dSr2)rtr��_enable_eagerloadsr�r�r
�PASSIVE_NO_FETCH_RELATEDrrArr
r��callable_for_pathrNrl�_load_for_path)rnr~rurvrwr]rrxr�r��
run_loaderrOr��flagsr;r;r<r�`s,
��z$ImmediateLoader.create_row_processorc	Cs�|rt|jj�}	||��f|	_|��}
|	f}nd}	|}
d}|j}|j�d�}
|D](\}}|j	}|s5||vrP|
j
||||
|d�}|ttj
fvrP|�|��|||�q(dS)Nr;r�)rMrNrO)r#rvr��_recurser~�_truncate_recursiver5rlr�rGr�rrr��get_impl�set_committed_value)rnr~rv�states�	load_onlyrwr�r�rO�new_optrNrMr5�
lazyloaderr��	overwriter�r'r;r;r<r��s>���
���zImmediateLoader._load_for_path)	r�r�r�r�rkr�r�r�r�r;r;rpr<r�Ss*r��subquerycs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZGdd�d�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�SubqueryLoaderr�crir2r�rmrpr;r<rk�rrzSubqueryLoader.__init__cCr�r�r�r�r;r;r<r��r�z#SubqueryLoader.init_class_attributecs�|}|j}t�|d�}|j�|�r!|j|dur!|j|j�}n||d�}|rK|j|jj|�t	|�t	��}|rJ�t
j�||d��7�n|�|j
}	��fdd�|	D�}
�|
|�fS)Nrr	cs&g|]}t�jdj�j|j��qS�r)�getattrrvr�r�r5r���leftmost_mapper�
new_subq_pathr;r<r��s�

��z0SubqueryLoader._get_leftmost.<locals>.<listcomp>)rvr3�_class_to_mapperrN�isarl�	_entities�entity_zeror{r�rr��coerce�
local_columns)rn�orig_query_entity_index�	subq_path�current_compile_state�is_root�given_subq_path�subq_mapper�
leftmost_prop�
additional�
leftmost_cols�
leftmost_attrr;r�r<�
_get_leftmost�s4
������zSubqueryLoader._get_leftmostcCs*|���d�}tj�tj�}|j�|j�|}|js0d|_|j	j
|gdd�t||d�D��R�|�dd�|D�|�
��}	|	|_|j}
|
durKd|_n|
durfdd�|	D�D]}t|	��|j�sed|_nqV|jsld	|_|jdur�|jr�t�|	|j�}|r�|�|	|�|�t���}
tj||
dd
�}|S)NFcSs h|]}|ddur|d�qS)r�Nr;)r��entr;r;r<�	<setcomp>s
�z?SubqueryLoader._generate_from_original_query.<locals>.<setcomp>)rtcSsg|]}tj�tjj|��qSr;)r*�	coercions�expect�roles�ColumnsClauseRole)r�r:r;r;r<r�0���z@SubqueryLoader._generate_from_original_query.<locals>.<listcomp>TcSsh|]}|j�qSr;)�tabler�r;r;r<r�?sr;��use_mapper_path)�_clone�	correlater�Query�__new__�__dict__�update�	_from_obj�_enable_assertionsrt�non_generativer�_adapt_col_list�_get_current_adapterrZ�distinct_target_key�	_distinctr�rFr��_has_row_limiting_clauser}r� expand_column_list_from_order_by�
_set_entities�set_label_styler,r�r3r%)rn�orig_compile_state�
orig_queryr�r��leftmost_relationship�orig_entity�q�q2�target_colsr��t�to_add�embed_q�
left_aliasr;r;r<�_generate_from_original_query�sX���������z,SubqueryLoader._generate_from_original_queryc
s�g}t|���}t|�D]'\}\}}|dkr)||ddj}|�|�r&|n|}	n|}	|�|	|jf�qt|�dkr=|�nt|dd�}
|
j	rL|
j
�ntj|
j
dd���j
j}��fdd�|D�}||�fS)	Nrr	r&r�Tr�cs g|]}t��jj|j��qSr;)r�rNr�r5r���parent_aliasrnr;r<r��s��z2SubqueryLoader._prep_for_joins.<locals>.<listcomp>)r�pairs�	enumerater]r�rLr5r�r(rr�r3r%rlr�)
rnrr��to_joinr�ir]r8�prev_mapper�	to_appendr�
local_cols�
local_attrr;rr<�_prep_for_joins[s*��
zSubqueryLoader._prep_for_joinscCs.t|�}|dkrt||dd��|�g}nu|dkr3t||dd��|�t||dd��|�g}nX|dkr�dd�|dd�D�}g}|rl|�d�}	t|	d|	d�}
|r`|
�|dd�}
n|
�|�}
|�|
�|sFt||dd��|dj�g|t||dd��|�g}|D]}
|�|
�}q�|S)Nr	rr&r�cSs:g|]}t|d�jst�|d�n|dj|df�qS)rr	)r(rr3r%r�)r��itemr;r;r<r��s	����z/SubqueryLoader._apply_joins.<locals>.<listcomp>)r�r��of_type�poprLrN�join)rnrrrr�effective_entity�ltj�middle�innerr�attrr;r;r<�_apply_joins�sF���
	�


������
zSubqueryLoader._apply_joinsc	CsB|j}|r|jr|t�|j|�|��f7}|�|�}|j|�}|Sr2)rzr�r3ryr�r��_with_current_path�options)	rnr~rr��rewritten_pathrrrw�new_optionsr;r;r<�_setup_options�s
��
	
zSubqueryLoader._setup_optionscs&�jjr�fdd�}|�|�j�}|S)Nc� |jtt��jj��7_dSr2��eager_order_by�tuplerrrlr�rgr�r;r<�_setup_outermost_orderby���zISubqueryLoader._setup_outermost_orderby.<locals>._setup_outermost_orderby)rlr�_add_context_option)rnrr-r;r�r<r-�s�z'SubqueryLoader._setup_outermost_orderbyc@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)zSubqueryLoader._SubqCollectionsz�Given a :class:`_query.Query` used to emit the "subquery load",
        provide a load interface that executes the query at the
        first moment a value is needed.

        �r�rOrar*�subq�_datacCs4|j|_|j|_|j|_|jpi|_||_d|_dSr2r0)rnr~r1r;r;r<rks
z(SubqueryLoader._SubqCollections.__init__cCs |jdur	|��|j�||�Sr2)r2�_loadrU)rnr5�defaultr;r;r<rU
s
z#SubqueryLoader._SubqCollections.getcCs�t�t�|_|j}|jdusJ�|�|j�}|jjr|�	�}t|�
|j
��}t�|dd��D]\}}|j|�
dd�|D��q.dS)NcSs|dd�S)Nr	r;��xr;r;r<r=sz7SubqueryLoader._SubqCollections._load.<locals>.<lambda>cs��|]}|dVqdS)rNr;�r��vvr;r;r<r���z8SubqueryLoader._SubqCollections._load.<locals>.<genexpr>)�collections�defaultdictrr2r1r��with_sessionra�_populate_existingr�r*�	itertools�groupby�extend)rnr�rowsr��vr;r;r<r3s�z%SubqueryLoader._SubqCollections._loadcCs|jdur|��dSdSr2)r2r3)rnr�r�r�r;r;r<r� s
�z&SubqueryLoader._SubqCollections.loaderN)	r�r�r�r�r�rkrUr3r�r;r;r;r<�_SubqCollections�s	
rDc	Cs�|j}|jjr|jjr
dS|j�|�}d|_||j}|�|j	dd�}	|	dur*|	}
n|j
}
|jj�dt
jjt
jjf�\}}|t
jju}
||}||}|jj�dtf|j�}t�|d�}|jrq|jjdurnt�d||f�|j}|j|dd�}|�||||
�\}}}}|�||||||�}t�|
�}|jj�|jdtf|d||fi�|_|�d�}|� ||�\}}}|j!|�}|�"|||||
�}|�#||||||
|�}|�$|�}|S)	NT�path_with_polymorphic)�subquery_pathsNr�ormz�subqueryloader for "%s" must invoke lambda callable at %r in order to produce a new query, decreasing the efficiency of caching for this statement.  Consider using selectinload() for more effective full-lambda cachingF)�legacy)%rtr�r��_for_refresh_stater��index�loaders_require_bufferingrlrUr
r�rrwr3r�r�r�r�_get_plugin_class_for_plugin�_is_lambda_elementrar^rr��	_resolved�_create_entities_collectionr�r
r�r�rO�_set_enable_single_critr�add_columnsr"r'r-)rnr~rurvr�rwrxrtr��with_poly_entityrr�r%r�r�compile_state_clsrr�r�rrrrrrr;r;r<�_setup_query_from_rowproc$s�	��
��
�����	��
�
��

�

��
	z(SubqueryLoader._setup_query_from_rowprocc	
s�|r|jjdur|jjjrt�dd�|jr"|�||||||�|�S|�||||j�\}	}
}	}	|
s3dSt	|jt
�s;dS|jj|j
jjsKt�d|��t|�dkr\t�|j|j�s[dSnt�|d|j�sgdS|�||||d|��}|durydS|jdus�J�||j}|jj}|�|jd�}
|
dur�|�||�}
|�|jd|
��r��fdd�|D�}|jr�|�|||
||�dS|� |||
||�dS)	Nz�The subqueryload loader option is not compatible with DML statements such as INSERT, UPDATE.  Only SELECT may be used.This warning will become an exception in a future release.�2.0�J'%s' does not support object population - eager loading cannot be applied.r	r�r;c�g|]}�j|�qSr;rgr��rxr;r<r�r1z7SubqueryLoader.create_row_processor.<locals>.<listcomp>)!rt�	statement�is_dmlr�warn_deprecatedr�r�r�r�r�rrNrVr5�impl�supports_populationr�r�r�r3�_entity_isar�rTr�rlr�rUr
rDr�r@�_create_collection_loader�_create_scalar_loader)rnr~rurvrwr]rrxr��_r�r1rr;r;rXr<r��s�����
���	��	

�
�z#SubqueryLoader.create_row_processorc�t|�|�����fdd����fdd�}|d��j�f�|d��j|f�|jr8|d��j�jf�dSdS)Ncs*���|�d�}|��j��|||�dS)Nr;)rUr�r5r�)r�r�r��
collection�r;rn�tuple_getterr;r<�load_collection_from_subqs�zKSubqueryLoader._create_collection_loader.<locals>.load_collection_from_subqc��j|vr
�|||�dSdSr2r�r�)rfrnr;r<�&load_collection_from_subq_existing_row�
�zXSubqueryLoader._create_collection_loader.<locals>.load_collection_from_subq_existing_rowr��existing�eager��
_tuple_getterrLr5�invoke_all_eagersr�)rnr~rr;rr�rhr;)r;rfrnrer<r_s
��z(SubqueryLoader._create_collection_loadercrb)NcsL���|�d�}t|�dkrt�d��|d}|��j��|||�dS)Nr2r	�LMultiple rows returned with uselist=False for eagerly-loaded attribute '%s' r)rUr�rr�r�r5r�)r�r�r�rc�scalarrdr;r<�load_scalar_from_subq-s��zCSubqueryLoader._create_scalar_loader.<locals>.load_scalar_from_subqcrgr2r�r�)rqrnr;r<�"load_scalar_from_subq_existing_row8rizPSubqueryLoader._create_scalar_loader.<locals>.load_scalar_from_subq_existing_rowr�rjrkrl)rnr~rr;rr�rrr;)r;rqrnrer<r`(s
��z$SubqueryLoader._create_scalar_loader)r�r�r�r�rkr�r�r
rr"r'r-rDrTr�r_r`r�r;r;rpr<r��s 1d/6"4	er��joinedcs�eZdZdZdZ�fdd�Zdd�Z			d!d	d
�Zdd�Zd
d�Z	dd�Z
dd�Z		d"d#dd�Zdd�Z
dd�Zdd�Zdd �Z�ZS)$�JoinedLoaderz[Provide loading behavior for a :class:`.Relationship`
    using joined eager loading.

    r�crir2r�rmrpr;r<rkOrrzJoinedLoader.__init__cCr�r�r�r�r;r;r<r�Sr�z!JoinedLoader.init_class_attributeNFc	Kst|jjsdS|r|jdur|jjrt�dd�n|jrd|_||j}d}
|r/|�	|||j
�nd}|durB|�|||||�\}}}
n0|�|j
d�s_|j
rW|jd|j
krVdSn|�|j�r_dS|�||||||||�\}}}
}d|_|�|j
dd�}|dur�t|�j}
nd}
||j}tj||j||||
|
|j|d	�	tj�|j�}|r�|dur�t�d
��dd�|jD�|_dSdS)
z@Add a left outer join to the statement that's being constructed.Nz�The joinedload loader option is not compatible with DML statements such as INSERT, UPDATE.  Only SELECT may be used.This warning will become an exception in a future release.rUTFr�r&rE)�with_polymorphic�parentmapper�chained_from_outerjoinz�Detected unaliased columns when generating joined load.  Make sure to use aliased=True or flat=True when using joined loading with with_polymorphic().cSsg|]}|dur|�qSr2r;r�r;r;r<r��sz,JoinedLoader.setup_query.<locals>.<listcomp>)r�r�rYrZrr[r@�multi_row_eager_loadersrl�_init_user_defined_eager_procr
�$_setup_query_on_user_defined_adapterr�r�r�r�r]�_generate_row_adapter�eager_adding_joinsrUr(�with_polymorphic_mappersr�r
�_setup_entity_query�NONE_SETr��secondary_columnsr�r�)rnrtrurvrwrxryrvrwrzru�user_defined_adapter�clauses�add_to_collectionrR�	has_nonesr;r;r<r|Xs��
��
�����������
����zJoinedLoader.setup_queryc
Cs�d|jvrdS|jj}|�|jdd�}|dur|S|jd}|dd�\}}|durEt|t�r5|j�|�}t	j
t	jj|j
||j
jdd�}n#|�|jd�r`|�|jd�}	t	j
t	jj|	|j
jd�}n|j�|j
d�}|�|d|�|S)N�eager_from_aliasF� user_defined_eager_row_processor���)�
selectabler�limit_on_entityrE)r)r�rvrNrUr
r�r�r��aliasr3�
ORMAdapter�_TraceAdaptRole�JOINEDLOAD_USER_DEFINED_ALIASr]rr�� JOINEDLOAD_PATH_WITH_POLYMORPHIC�_polymorphic_adaptersr�)
rnrwrt�target_attributesrvrxr��root_mapperr8rRr;r;r<ry�sP
�

������z*JoinedLoader._init_user_defined_eager_proccCsV|�|�}|r|r|�|�}|�|jd|�n|r#|}|�|jd|�|j}|||fS)Nr�)�_get_entity_clauses�wrapr�r
�primary_columns)rnr~r�rvrxr�r�r;r;r<rz	s"

��
z1JoinedLoader._setup_query_on_user_defined_adapterc	Cs|�|jdd�}	|	r
|	}
n"t|j�}|jr|j}nd}tj|j|dur)|j	dd�ndddd�}
t|
�}
|
j
d|ftjtjj
|
|jjdddd�}|jsLJ�|durY|j�d|jj�n|jj}|sad}|j�|j||||||||rr|jnd	f	�|j}|�|jd
|�||||fS)NrET)�flat)r�r�r��joinedloader_ormadapterF)r�adapt_required�allow_label_resolve�anonymize_labels�	innerjoinr;�eager_row_processor)rUr
r(r�rr�r3r%r]�_anonymous_fromclause�_memor�r��JOINEDLOAD_MEMOIZED_ADAPTERrr�rlr��create_eager_joinsrL�_create_eager_joinr�r�r�)rnrtr�rvrwrxryrvrwrR�to_adapt�insp�alt_selectable�
to_adapt_inspr�r�r�r;r;r<r{,	sd�
���
����z"JoinedLoader._generate_row_adapterc
	sP|dur|j}
n|}
|jo|j}d}||jvr?|s?|jr?t�|j|j�}
t|
�dkr/t	�
d��|
r?|j|
d}|
d|}}|durI||j}}|j�||�}|r�t|dd�rq|j
�|
��j�rc|
n�j�}t|j�j�j�}nttj�j|jdd��j�j�}n�j}|js�J�|p�|p�|dkp�|jj}|	}|j�d	�jfd
�}|r�|t�fdd�|D��7}|r�tj||j
||p�|jjp�|o�t|tj��j|�j|d
�}n�� ||d||||�}||j|<|j|_!|�s
t�"�jj#�D]}|
j$j%�&|��r|�r|j'|}|�(||j)�q�jj*�r&|j+t|j,�-t.�/�jj*���7_+dSdS)Nr	z�Can't identify which query entity in which to joined eager load from.   Please use an exact match when specifying the join path.rrFTr��unnested�additional_entity_criteriar;c3s"�|]}|jr|��j�VqdSr2)�propagate_to_loaders�_resolve_where_criteriar])r��aer�r;r<r��	s��

�z2JoinedLoader._create_eager_join.<locals>.<genexpr>��isouter�
_left_memo�_right_memor�r�)0r]rx�_should_nest_selectable�eager_joins�from_clausesr�#find_left_clause_that_matches_givenr�r�r�r��
setdefaultr��aliased_insp�_entity_for_mapperr�rNr�r5rlr3r%rr��represents_outer_join�global_attributesrUr+�_ORMJoinr�r*�Join�_splice_nested_inner_join�stop_on�
_find_columns�primaryjoin�persist_selectabler{�contains_columnrhrsr�rr*�_target_adapter�copy_and_processrr)rnrtrurvrxrvr�r�rwrLr��should_nest_selectable�query_entity_key�indexes�clause�default_towrap�towrap�efm�onclause�attach_on_outside�extra_join_criteriar��	eagerjoinr�r;r�r<r�{	s��
������
��
��	
���
�
���
�
�
��
���zJoinedLoader._create_eager_join�entity_inside_join_structure�#Union[Mapper, None, Literal[False]]�detected_existing_path�$Optional[path_registry.PathRegistry]c	
Cs�||dusJ�|durt|tj�sJ�t|tjj�r'|�|||j||||�St|tj�r�|j}	|j|||j	||||	durB|	dj
ndd�}
|
durj|jsV|
jsV|�|
�}ntj|j
|
|j|j|jd�}|
j|_|S|j|||j
||||j|	d�}
|
dur�tj|
|j	|j|j|jd�}|
j|_|S|dur�	Jd��dS|�|�s�dS|r�t|�d	kr�|d
|us�J�|dd�|jdd�kr�dStj||j|d|||dj
|d�S)
Nr�Fr�)r�)r�r�)r�r�)r�r�z9assertion failed attempting to produce joined eager loadsr&���rr�)r�r3r�r*r��FromGroupingr��elementr��rightr]r��_splice_into_center�leftr�r�r�r�r�rvr�)rnrv�entity_we_want_to_splice_onto�join_objr�r�rLr�r��join_right_path�target_joinr�r;r;r<r�
s��	
�������
$�z&JoinedLoader._splice_nested_inner_joinc	Cs�|j}|r
|�|||j�nd}|dur(|}|jr!|r!|�|j�}n|jr'|j}n
|�|jd�}|dur5dS|j�||�r>|SdS)NFr�)rtryr
�compound_eager_adapterr�rUr]�_result_has_identity_key)	rnr~rrxrvrwrtr��	decoratorr;r;r<�_create_eager_adapter�
s0���
���z"JoinedLoader._create_eager_adapterc	

Cs�|jjjsdS|jj|jjjst�	d|��|j
rd|_||j}	|�
||||	|�}
|
durW|j}t�||j|||	|j|
�}|j
sM|�||||�dS|�||||�dS|j�d��||||||||�dS)NrVTFr�)rtr�r�rNrVr5r\r]r�r�r@�loaders_require_uniquingrlr�r
�_instance_processorr]r�r`r_r�r�)
rnr~rurvrwr]rrxr��our_path�
eager_adapterr5�	_instancer;r;r<r��
sT
��

��	���z!JoinedLoader.create_row_processorcsv���fdd�}���fdd�}�fdd�}|d�|j|f�|d�|j|f��jr9|d	�|j|f�dSdS)
NcsJt�||��}t�|d�}|�j|�f<�|�}|dur#|�|�dSdS�N�append_without_event�r
r�r�UniqueAppenderrL)r�r�r�rc�result_list�inst�r�r~r5r;r<�#load_collection_from_joined_new_row*s��zSJoinedLoader._create_collection_loader.<locals>.load_collection_from_joined_new_rowcsh|�f�jvr�j|�f}nt�||��}t�|d�}|�j|�f<�|�}|dur2|�|�dSdSr�r�)r�r�r�r�rcr�r�r;r<�(load_collection_from_joined_existing_row7s���zXJoinedLoader._create_collection_loader.<locals>.load_collection_from_joined_existing_rowc��|�dSr2r;r��r�r;r<� load_collection_from_joined_execJ�zPJoinedLoader._create_collection_loader.<locals>.load_collection_from_joined_execr�rjrk�rLr5rn)rnr~r5r�r�r�r�r�r;r�r<r_)s
����z&JoinedLoader._create_collection_loadercst��fdd�}���fdd�}�fdd�}|d��j|f�|d��j|f�|jr8|d	��j|f�dSdS)
Ncs�|�|�<dSr2r;r�)r�r5r;r<�load_scalar_from_joined_new_rowYszKJoinedLoader._create_scalar_loader.<locals>.load_scalar_from_joined_new_rowcs>�|�}�|vr||�urt�d��dSdS||�<dS)Nro)rr�)r�r�r�rj�r�r5rnr;r<�$load_scalar_from_joined_existing_row^s���
zPJoinedLoader._create_scalar_loader.<locals>.load_scalar_from_joined_existing_rowcr�r2r;r�r�r;r<�load_scalar_from_joined_execqr�zHJoinedLoader._create_scalar_loader.<locals>.load_scalar_from_joined_execr�rjrkr�)rnr~r5r�r�r�r�r�r;r�r<r`Xs���z"JoinedLoader._create_scalar_loader)NNF)FN)r�r�r�r�)r�r�r�r�r�rkr�r|ryrzr{r�r�r�r�r_r`r�r;r;rpr<rtDs.
�9O*�.$>/rt�selectincsteZdZdZe�dgd��ZdZ�fdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�SelectInLoader)r��	omit_join�
_parent_alias�_query_info�_fallback_query_info�	queryinfo)�load_only_child�load_with_join�in_expr�pk_cols�zero_idx�child_lookup_colsi�cs�t��||�|jj|_|jjtju}|jjdur|jj|_n|j�d�}|r,|j	|_n|j
jdj|j
dd|j
jd�|_|jrU|rN|��|_|��|_dS|��|_dS|��|_dS)Nr�rTFr)rjrkrlr�rZrr r�r�r�rNrr�r�r�_init_for_omit_join_m2or��_init_for_joinr��_init_for_omit_join)rnrNro�is_m2or�rpr;r<rk�s,
�
�
zSelectInLoader.__init__cs�t�jjj������fdd�t��D���fdd��jjD�}}t|�dkr1t	j
|�}d}n|d}d}��dd|||d�S)	Nc3s2�|]}�jj�|d�D]	}|�|fVqqdS)r;N)rNrrU)r�r��equiv��pk_to_fkrnr;r<r��s��
��z5SelectInLoader._init_for_omit_join.<locals>.<genexpr>csg|]
}|�vr�|�qSr;r;�r�r�)rr;r<r��sz6SelectInLoader._init_for_omit_join.<locals>.<listcomp>r	FrT)rGrlr�local_remote_pairsr�rrNr�r�r*�tuple_�
query_info)rnr��fk_colsr�rr;rr<r�s��

�
z"SelectInLoader._init_for_omit_joincsb|jj}t|�dkrtj|�}d}n|d}d}|j�d���fdd�|D�}|�dd||||�S)Nr	FrTr�crWr;rTrU�r�r;r<r��r1z:SelectInLoader._init_for_omit_join_m2o.<locals>.<listcomp>)r]r�r�r*rrlr�r)rnr�r�r�lookup_colsr;rr<r�s
�z&SelectInLoader._init_for_omit_join_m2ocsjt|jj�|_t|j���fdd�|jjD�}t|�dkr%tj|�}d}n|d}d}|�	dd|||d�S)Nc�g|]}��|��qSr;��_adapt_elementr	��pa_inspr;r<r���
�z1SelectInLoader._init_for_join.<locals>.<listcomp>r	FrT)
r%rNrYr�r(r�r�r*rr)rnr�r�rr;rr<r�s

�
zSelectInLoader._init_for_joincCr�r�r�r�r;r;r<r��r�z#SelectInLoader.init_class_attributec	Cs|jr|�||||||||�S|j||||jd�\}	}
}}|
s!dS|jjjs(dS|jj|j	j
js8t�
d|��t|�dkrIt�|j|j�sHdSnt�|d|j�sTdS|	}
||j}|�|jdd�}|durlt|�}n|j}tj�||
|j|j|j||||�	dS)Nr�rVr	r�rE)r�r�r�r�rtr�r�rNrVr5r\r]r�r�r�r3r^r�rlrUr
r(r�r
r�r�r�)rnr~rurvrwr]rrxr�r�r�rOr��
selectin_pathr�rRrr;r;r<r��sl�
��
��	�
�
�z#SelectInLoader.create_row_processorc	s�|r	�j|vr	dS�j}	|	jrRt�t�}
g}�j�|D]6\�}�j�t���fdd�|	j	D��}
t
j|
vr:�j}	nd|
vrI|
|
�
��|f�q|�
��|f�q|	js\dd�|D�}
|	j}|	j}|	jsv�jrv�fdd�|D�}��|�}tjdg|�R�}|��}���}tj||gttjd�d�d	�}|	js�|���}n|��j��t�j�jj�� ���}|�!|�"t#�$d
���}�j%j&}|�j}|�j'ur�|j(}n|j(}�j'j(}�fdd�t)||�D�}|r�|j*r�|t�+�|�,���f7}|dur�|�-�}|j.|�}|�/d|i�}�j0�r|j1d
d�}�jj2�r=|	j�s0�jj2}�j�r*�fdd�|D�}|j2|�}n
�fdd�}|�3|�j�}|	j�rM��4|
||	|�|�dS��5|
|	|�|�dS)Nc3s$�|]
}�j��|tjd�VqdS)rSN)r8r
�PASSIVE_NO_FETCH)r��lk)r]r��
state_dictr;r<r�Vs���
�z0SelectInLoader._load_for_path.<locals>.<genexpr>cSs$g|]\}}|jd||j|f�qS)r	)r5rG)r�r�r�r;r;r<r�ss��z1SelectInLoader._load_for_path.<locals>.<listcomp>crr;rr	�rr;r<r��rrVrG)�compile_state_plugin�plugin_subject)rZr\r�r[�primary_keyscsg|]
\}}|��|��qSr;)�'_adapt_cached_option_to_uncached_option)r��orig_opt�uncached_opt)r~r;r<r��s���r`T)r�crr;rrrr;r<r��s��cr(r2r)r,r�r;r<r-�r.z?SelectInLoader._load_for_path.<locals>._setup_outermost_orderby)6r5r�r�r;r<rrNrGr+rrr�r�rLr�r�r�rrr3�Bundleror-rpr,rrqrtr�rr�rlr�filter�in_r*r#rt�select_statement�user_passed_queryrz�zipr�ryr�r�r$�_update_compile_optionsr�rOrr/�_load_via_child�_load_via_parent)rnr~rvr�r�rrwr�rOr�
our_states�none_statesr��
related_identr�r��
bundle_ent�
bundle_sql�
entity_sqlrrr�r&�cached_options�uncached_optionsr*r-r;)r~rr]rnr�rr<r�>s�
�
��
�
��
��


��
	��


���	
�zSelectInLoader._load_for_pathcs�|j}t|�}|r_|d|j�}	||jd�}dd�|jj|d�fdd�|	D�i|d���D�}
|	D]*}|
�|d�}||D]\}
}}|sK|j|vrKq>|
�|j��	|
||sW|n|g�q>q2|s	|D]\}
}}|sn|j|vrnqa|
�|j��	|
|d�qadS)NrcSsi|]\}}||�qSr;r;)r�r�rCr;r;r<�
<dictcomp>!
s��z2SelectInLoader._load_via_child.<locals>.<dictcomp>rcsg|]}�jr|dn|�qSr��r)r�r5�rr;r<r�&
r�z2SelectInLoader._load_via_child.<locals>.<listcomp>�r*rO)
r@�sorted�
_chunksizer�r�r!rUr5r�r�)rnr*r+rrr~rOr@�our_keys�chunk�datar5�related_objr�r�r�r;r4r<r(
sB	���	����"�zSelectInLoader._load_via_childcs$|j}|rdnd}|r�|d|j�}||jd�}�fdd�|D�}	t�t�}
t�|jj|d|	i|d��	�dd��D]\}}|
|�
d	d
�|D��q:|D]>\}
}}}|s[|j|vr[qM|
�|
|�}|s�|r�t
|�dkrrt�d|�|�|j��|||d�qM|�|j��|||�qM|sdSdS)
Nr;rcs&g|]\}}}}�jr|dn|�qSr�r3)r�r5r�rr�r4r;r<r�R
s
��z3SelectInLoader._load_via_parent.<locals>.<listcomp>rr5cSs|dSr�r;r5r;r;r<r=^
sz1SelectInLoader._load_via_parent.<locals>.<lambda>csr7)r	Nr;r8r;r;r<r�`
r:z2SelectInLoader._load_via_parent.<locals>.<genexpr>r	ro)r@r7r;r<rr?r@r�r�r!rAr5rUr�rr�r�r�)rnr*rrr~rOr@�
_empty_resultr9rr:r�rCr5r�rr�rcr;r4r<r)H
sJ
�
����
���zSelectInLoader._load_via_parent)r�r�r�r�r;�
namedtuplerr7rkrrrr�r�r�r(r)r�r;r;rpr<r�~s"�PT7r�csT�fdd���fdd�}�fdd�}tj|d|dddd	�tj|d
|dddd	�dS)NcsT|dur(|j�jkr(|�t�|��}|r(||ur(tjdt�|�|j�fdd��|S)NzsInstance %s is already associated with an instance of %s via its %s attribute, and is only allowed a single parent.�bbf1)�code)	r5�	hasparentr
�instance_stater�r�r3�instance_strrY)r�r'�oldvalue�	initiatorr@)r8r;r<�	_do_check{
s��z*single_parent_validator.<locals>._do_checkcs�||d|�Sr2r;)r�r'rD�rEr;r<rL�
�z'single_parent_validator.<locals>.appendcs�||||�Sr2r;)r�r'rCrDrFr;r<�set_�
rGz%single_parent_validator.<locals>.set_rLT)�raw�retvalrGr�)r'�listen)r7r8rLrHr;)rEr8r<rMz
s
�rM)NNNNFN)Wr��
__future__rr;r?�typingrrrrrr�r
rr�rr
rrrrrrr3�baserrrrrrrr~rrrrrr r�r!r�r"rjr#r$r%r'r�r(r)r*rr+�sql.selectabler,r-�util.typingr.r]r/r0�sql.elementsr1rc�ColumnProperty�strategy_forrf�class_loggerr�r�r�r�r�r�r��
MemoizedSlots�
Identifiedr�r�r�r�r�rtr�rMr;r;r;r<�<module>s�	
�Q+ZW�0%
&

�24Ld=}