a
    c	g                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 d	d
l
mZ d	dl
mZ d	dlmZ d	dlmZ erddlmZ ddlmZ ddlmZ e	dedZeefZG dd dejZeZG dd dejZG dd dejZG dd dejZG dd dejZ G dd deZ!G d d! d!eZ"G d"d# d#ejZ#G d$d% d%ejZ$G d&d' d'ejZ%d(d)d*d+d,Z&e'd-d(d.d*d/d0Z(d1S )2zSQLAlchemy ORM exceptions.    )annotations)Any)Optional)Tuple)Type)TYPE_CHECKING)TypeVar   )exc)util)MultipleResultsFound)NoResultFound   )LoaderStrategy)MapperProperty)InstanceState_T)boundc                   @  s   e Zd ZdZdS )StaleDataErroraa  An operation encountered database state that is unaccounted for.

    Conditions which cause this to happen include:

    * A flush may have attempted to update or delete rows
      and an unexpected number of rows were matched during
      the UPDATE or DELETE statement.   Note that when
      version_id_col is used, rows in UPDATE or DELETE statements
      are also matched against the current known version
      identifier.

    * A mapped object with version_id_col was refreshed,
      and the version number coming back from the database does
      not match that of the object itself.

    * A object is detached from its parent object, however
      the object was previously attached to a different parent
      identity which was garbage collected, and a decision
      cannot be made if the new parent was really the most
      recent "parent".

    N__name__
__module____qualname____doc__ r   r   U/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/sqlalchemy/orm/exc.pyr   #   s   r   c                   @  s   e Zd ZdZdS )
FlushErrorz0A invalid condition was detected during flush().Nr   r   r   r   r   r   ?   s   r   c                   @  s   e Zd ZdZdS )UnmappedErrorz?Base for exceptions that involve expected mappings not present.Nr   r   r   r   r   r   C   s   r   c                   @  s   e Zd ZdZdS )ObjectDereferencedErrorzPAn operation cannot complete due to an object being garbage
    collected.

    Nr   r   r   r   r   r   G   s   r   c                   @  s   e Zd ZdZdZdS )DetachedInstanceErrorzSAn attempt to access unloaded attributes on a
    mapped instance that is detached.Zbhk3N)r   r   r   r   coder   r   r   r   r   N   s   r   c                   @  s:   e Zd ZdZedddddddZd	d
ddZdS )UnmappedInstanceErrorz;An mapping operation was requested for an unknown instance.sqlalchemy.orm.baseNobjectOptional[str])objmsgc                 C  s   t jj}|sxz*|t| tt|}d||f }W n@ tyv   dtt| d}t|trr|dt| 7 }Y n0 t	| | d S )NzClass %r is mapped, but this instance lacks instrumentation.  This occurs when the instance is created before sqlalchemy.orm.mapper(%s) was called.Class '' is not mappedz;; was a class (%s) supplied where an instance was required?)
r   	preloadedorm_baseZclass_mappertype_safe_cls_nameUnmappedClassError
isinstancer   __init__)selfr%   r&   basenamer   r   r   r/   X   s$    

zUnmappedInstanceError.__init__r   returnc                 C  s   | j d | jd ffS Nr   	__class__argsr0   r   r   r   
__reduce__o   s    z UnmappedInstanceError.__reduce__)Nr   r   r   r   r   preload_moduler/   r:   r   r   r   r   r!   U   s   r!   c                   @  s0   e Zd ZdZddddddZdd	d
dZdS )r-   z8An mapping operation was requested for an unknown class.NzType[_T]r$   )clsr&   c                 C  s   |st |}t| | d S )N)_default_unmappedr   r/   )r0   r=   r&   r   r   r   r/   v   s    zUnmappedClassError.__init__r   r3   c                 C  s   | j d | jd ffS r5   r6   r9   r   r   r   r:   {   s    zUnmappedClassError.__reduce__)N)r   r   r   r   r/   r:   r   r   r   r   r-   s   s   r-   c                   @  s:   e Zd ZdZedddddddZd	d
ddZdS )ObjectDeletedErrora  A refresh operation failed to retrieve the database
    row corresponding to an object's known primary key identity.

    A refresh operation proceeds when an expired attribute is
    accessed on an object, or when :meth:`_query.Query.get` is
    used to retrieve an object which is, upon retrieval, detected
    as expired.   A SELECT is emitted for the target row
    based on primary key; if no row is returned, this
    exception is raised.

    The true meaning of this exception is simply that
    no row exists for the primary key identifier associated
    with a persistent object.   The row may have been
    deleted, or in some cases the primary key updated
    to a new value, outside of the ORM's management of the target
    object.

    r"   NzInstanceState[Any]r$   )stater&   c                 C  s,   t jj}|sd|| }tj| | d S )NzDInstance '%s' has been deleted, or its row is otherwise not present.)r   r)   r*   Z	state_strsa_excInvalidRequestErrorr/   )r0   r@   r&   r1   r   r   r   r/      s    zObjectDeletedError.__init__r   r3   c                 C  s   | j d | jd ffS r5   r6   r9   r   r   r   r:      s    zObjectDeletedError.__reduce__)Nr;   r   r   r   r   r?      s   r?   c                   @  s   e Zd ZdZdS )UnmappedColumnErrorz5Mapping operation was requested on an unknown column.Nr   r   r   r   r   rC      s   rC   c                   @  s&   e Zd ZdZdddddddd	Zd
S )LoaderStrategyExceptionz2A loader strategy for an attribute does not exist.	Type[Any]zMapperProperty[Any]z#Optional[Type[MapperProperty[Any]]]zOptional[Type[LoaderStrategy]]zTuple[Any, ...])applied_to_property_typerequesting_property
applies_toactual_strategy_typestrategy_keyc              
   C  s\   |d u r t j| d||f  n8|d us,J t j| dt||t|t|f  d S )NzCan't find strategy %s for %szuCan't apply "%s" strategy to property "%s", which is a "%s"; this loader strategy is intended to be used with a "%s".)rA   rB   r/   r   Zclsname_as_plain_name)r0   rF   rG   rH   rI   rJ   r   r   r   r/      s$    z LoaderStrategyException.__init__N)r   r   r   r   r/   r   r   r   r   rD      s   rD   rE   str)r=   r4   c                 C  sJ   zd | j| jf}W n. tyD   t| dd }|d u r@t| }Y n0 |S )N.r   )joinr   r   AttributeErrorgetattrrepr)r=   cls_namer   r   r   r,      s    r,   r"   r$   c              	   C  sX   t jj}z|| j}W n ttft y6   i }Y n0 t| }|sPd| dS d S d S )Nr'   r(   )	r   r)   r*   Zmanager_of_classmappersr-   	TypeErrorNO_STATEr,   )r=   r1   rR   r2   r   r   r   r>      s    

r>   N))r   
__future__r   typingr   r   r   r   r   r    r
   rA   r   r   r   Z
interfacesr   r   r@   r   r   rN   KeyErrorrT   ZSQLAlchemyErrorr   ZConcurrentModificationErrorr   rB   r   r   r   r!   r-   r?   rC   rD   r,   r<   r>   r   r   r   r   <module>   s>   $!