U ag@spdZddlmZddlmZddlmZddlmZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)zgprivate module containing functions used for copying data between instances based on join conditions. ) attributes)exc)utilc Cs|j}|j}|D]\} } z(|j| } |j| jj||tj} Wn6tj k rv} zt d|| || | W5d} ~ XYnXz(|j| } |j| jj ||| dWn6tj k r} zt d|| || | W5d} ~ XYnX|r| j r| j r| | rd|jd|| f<qdS)NFTZ pk_cascaded)dict_columntopropertymanagerkeyimplgetr PASSIVE_OFFrUnmappedColumnError_raise_col_to_propset primary_keyZ references)source source_mapperdest dest_mappersynchronize_pairs uowcommitZflag_cascaded_pks source_dictZ dest_dictlrpropvalueerrrTC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\orm\sync.pypopulates4   $ $rc Cs|D]\}}z|j|}||j}Wn6tjk rZ}ztd|||||W5d}~XYnXz|j|}|||j<Wqtjk rtd||||YqXqdS)NFT)rr rr r)rrrrrrrrrrrbulk_populate_inherit_keys>s  $ r c Cs|D]\}}|jr>|||j|tjkr>td|t|fz|||j|dWqtj k r}zt dd||||W5d}~XYqXqdS)NzKDependency rule tried to blank-out primary key column '%s' on instance '%s'T) r_get_state_attr_by_columnrorm_utilZ _none_setAssertionErrorZ state_strZ_set_state_attr_by_columnrr r)rrrrrrrrrclearNs   r$c Cs|D]\}}z*|||}|j||j|tjd}Wn6tjk rl} ztd||d|| W5d} ~ XYnX|||j <||||j <qdSN)ZpassiveF) Z_get_committed_attr_by_columnobjr!rrr rr rr ) rrrZ old_prefixrrrZoldvaluerrrrrupdate`s   $ r'c Csn|D]d\}}z|j||j|tjd}Wn6tjk r\}ztd||d||W5d}~XYnX|||j<qdSr%)r!rrr rr rr )rrZdict_rrrrrrrr populate_dictos  $r(c Csz|D]p\}}z|j|}Wn6tjk rP}ztd||d||W5d}~XYnX|||jtj}t|j rdSqdS)zpreturn true if the source object has changes from an old to a new value on the given synchronize pairs FNT) rrr rZget_attribute_historyr rZPASSIVE_NO_INITIALIZEboolZdeleted) rrrrrrrrhistoryrrrsource_modified{s $ r+cCsD|r"tjtd||f|dntjtd|||f|ddS)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).)Zreplace_contextzCan'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).)rZraise_rr )ZisdestrZ source_columnrZ dest_columnrrrrrs" rN) __doc__rrrr"rr r$r'r(r+rrrrrs    +