U
    [h                     @  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 n6 tj	k
rv } zt
d||	||
| W 5 d }~X Y nX z(|j|
 }|j|j j|||d  W n6 tj	k
r } zt
d||	||
| W 5 d }~X Y nX |r|	jr|
jr|
|	rd|jd||
f< qd S )NFTpk_cascaded)dict_columntopropertymanagerkeyimplgetr   PASSIVE_OFFr   UnmappedColumnError_raise_col_to_propsetprimary_key
references
attributes)sourcesource_mapperdestdest_mappersynchronize_pairs	uowcommitZflag_cascaded_pkssource_dict	dest_dictlrpropvalueerr r"   W/var/www/html/timesheet/backend/venv/lib/python3.8/site-packages/sqlalchemy/orm/sync.pypopulate   s4    	
  $
$r$   c                 C  s   |D ]\}}z|j | }| |j }W n6 tjk
rZ } ztd||||| W 5 d }~X Y nX z|j | }|| |j< W q tjk
r } ztd||||| W 5 d }~X Y qX 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krJtd| d| dt|  dz|| | j|d  W q tj	k
r } zt
dd |||| W 5 d }~X Y qX 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_util	_none_setAssertionError	state_str_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 n6 tjk
rl }	 ztd||d ||	 W 5 d }	~	X Y nX |||j	< ||||j	 < qd S N)passiveF)
_get_committed_attr_by_columnobjr'   r   r   r   r   r   r   r   )
r   r   r   Z
old_prefixr   r   r   oldvaluer    r!   r"   r"   r#   updatec   s         
$
r3   c                 C  sn   |D ]d\}}z|j | | j|tjd}W n6 tjk
r\ } ztd||d || W 5 d }~X Y nX |||j< qd S r.   )r'   r   r   r   r   r   r   r   )r   r   dict_r   r   r   r    r!   r"   r"   r#   populate_dictr   s       
$r5   c           	      C  sz   |D ]p\}}z|j | }W n6 tjk
rP } ztd||d|| W 5 d}~X Y nX | ||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   get_attribute_historyr   r   PASSIVE_NO_INITIALIZEbool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 )NzCan'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).zCan'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-   r3   r5   r;   r   r"   r"   r"   r#   <module>
   s   +