a
    •˜ëj“  ã                   @  sp   d Z ddlmZ ddlmZ ddlmZ ddlmZ dd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zgprivate module containing functions used for copying data
between instances based on join conditions.

é    )Úannotationsé   )Úexc)Úutil)ÚPassiveFlagc                 C  s  | j }|j }|D ]ö\}	}
z(|j|	 }| j|j j | |tj¡}W n8 tj	yx } zt
d||	||
|ƒ W Y d }~n
d }~0 0 z(|j|
 }|j|j j |||d ¡ W n8 tj	yÚ } zt
d||	||
|ƒ W Y d }~n
d }~0 0 |r|	jr|
jr|
 |	¡rd|jd||
f< qd S )NFTZpk_cascaded)ÚdictÚ_columntopropertyÚmanagerÚkeyÚimplÚgetr   ÚPASSIVE_OFFr   ÚUnmappedColumnErrorÚ_raise_col_to_propÚsetÚprimary_keyZ
referencesÚ
attributes)ÚsourceÚsource_mapperÚdestÚdest_mapperÚsynchronize_pairsÚ	uowcommitZflag_cascaded_pksÚsource_dictZ	dest_dictÚlÚrÚpropÚvalueÚerr© r   úR/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/orm/sync.pyÚpopulate   s0    	
ÿ(
(ÿþýür!   c                 C  s¶   |D ]¬\}}z|j | }| |j }W n8 tjy\ } ztd|||||ƒ W Y d }~n
d }~0 0 z|j | }|| |j< W q tjy® } ztd|||||ƒ W Y d }~qd }~0 0 qd S )NFT)r   r
   r   r   r   )r   r   r   r   r   r   r   r   r   r   r    Úbulk_populate_inherit_keysA   s    
(
r"   c                 C  s    |D ]–\}}|j rJ| | | j|¡tjvrJtd|› d|› dt | ¡› d�ƒ‚z| | | j|d ¡ W q tj	y˜ } zt
dd ||||ƒ W Y d }~qd }~0 0 qd S )NzDependency rule on column 'z)' tried to blank-out primary key column 'z' on instance 'ú'T)r   Ú_get_state_attr_by_columnr   Úorm_utilZ	_none_setÚAssertionErrorZ	state_strZ_set_state_attr_by_columnr   r   r   )r   r   r   r   r   r   r   r   r    ÚclearQ   s$    ÿÿþþþÿr'   c           
      C  sŽ   |D ]„\}}z*|  |  ¡ |¡}|j| | j|tjd�}W n8 tjyn }	 ztd||d ||	ƒ W Y d }	~	n
d }	~	0 0 |||j	< ||||j	 < qd S ©N)ZpassiveF)
Z_get_committed_attr_by_columnÚobjr$   r   r   r   r   r   r   r
   )
r   r   r   Z
old_prefixr   r   r   Zoldvaluer   r   r   r   r    Úupdatec   s    ÿÿ
(
r*   c                 C  sp   |D ]f\}}z|j | | j|tjd�}W n8 tjy^ } ztd||d ||ƒ W Y d }~n
d }~0 0 |||j< qd S r(   )r$   r   r   r   r   r   r   r
   )r   r   Zdict_r   r   r   r   r   r   r   r    Úpopulate_dictr   s    ÿ
(r+   c           	      C  s|   |D ]r\}}z|j | }W n8 tjyR } ztd||d||ƒ W Y d}~n
d}~0 0 |  ||jtj¡}t|j	ƒr dS qdS )zpreturn true if the source object has changes from an old to a
    new value on the given synchronize pairs

    FNT)
r   r   r   r   Zget_attribute_historyr
   r   ZPASSIVE_NO_INITIALIZEÚboolZdeleted)	r   r   r   r   r   r   r   r   Úhistoryr   r   r    Úsource_modified~   s    (
ÿ
r.   c                 C  s4   | rt  d||f ¡|‚nt  d|||f ¡|‚d S )NzÑCan't execute sync rule for destination column '%s'; mapper '%s' does not map this column.  Try using an explicit `foreign_keys` collection which does not include this column (or use a viewonly=True relation).zØCan't execute sync rule for source column '%s'; mapper '%s' does not map this column.  Try using an explicit `foreign_keys` collection which does not include destination column '%s' (or use a viewonly=True relation).)r   r   )Zisdestr   Zsource_columnr   Zdest_columnr   r   r   r    r   ‘   s    üÿúûÿùr   N)Ú__doc__Ú
__future__r   Ú r   r   r%   Úbaser   r!   r"   r'   r*   r+   r.   r   r   r   r   r    Ú<module>
   s   +