o
    RcP                     @   s  d Z ddlmZ ddlmZ ddlmZ ddlm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 Zeddd ZdS ) zSQLAlchemy ORM exceptions.   )exc)util)MultipleResultsFound)NoResultFoundc                   @      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   4D:\Flask\env\Lib\site-packages\sqlalchemy/orm/exc.pyr          r   c                   @   r   )
FlushErrorz0A invalid condition was detected during flush().Nr   r   r   r   r   r   /   r   r   c                   @   r   )UnmappedErrorz?Base for exceptions that involve expected mappings not present.Nr   r   r   r   r   r   3   r   r   c                   @   r   )ObjectDereferencedErrorzPAn operation cannot complete due to an object being garbage
    collected.

    Nr   r   r   r   r   r   7   r   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   >   s    r   c                   @   ,   e Zd ZdZeddddZdd ZdS )	UnmappedInstanceErrorz;An mapping operation was requested for an unknown instance.sqlalchemy.orm.baseNc                 C   s   t jj}|s8z|t| tt|}d||f }W n ty7   tt|}t|tr5|dt| 7 }Y nw 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.z;; was a class (%s) supplied where an instance was required?)r   	preloadedorm_baseZclass_mappertype_safe_cls_nameUnmappedClassError_default_unmapped
isinstancer   __init__)selfobjmsgbasenamer   r   r   r   H   s(   
zUnmappedInstanceError.__init__c                 C      | j d | jd ffS N    	__class__argsr    r   r   r   
__reduce___      z UnmappedInstanceError.__reduce__Nr	   r
   r   r   r   preload_moduler   r,   r   r   r   r   r   E   s
    r   c                   @   s"   e Zd ZdZdddZdd ZdS )r   z8An mapping operation was requested for an unknown class.Nc                 C   s   |st |}t| | d S r.   )r   r   r   )r    clsr"   r   r   r   r   f   s   zUnmappedClassError.__init__c                 C   r%   r&   r(   r+   r   r   r   r,   k   r-   zUnmappedClassError.__reduce__r.   )r	   r
   r   r   r   r,   r   r   r   r   r   c   s    
r   c                   @   r   )	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   Nc                 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   	state_strsa_excInvalidRequestErrorr   )r    stater"   r#   r   r   r   r      s   zObjectDeletedError.__init__c                 C   r%   r&   r(   r+   r   r   r   r,      r-   zObjectDeletedError.__reduce__r.   r/   r   r   r   r   r2   o   s
    r2   c                   @   r   )UnmappedColumnErrorz5Mapping operation was requested on an unknown column.Nr   r   r   r   r   r7      r   r7   c                   @   s   e Zd ZdZdd ZdS )LoaderStrategyExceptionz2A loader strategy for an attribute does not exist.c              
   C   sR   |d u rt j| d||f  d S 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".)r4   r5   r   r   Zclsname_as_plain_name)r    Zapplied_to_property_typeZrequesting_propertyZ
applies_toZactual_strategy_typeZstrategy_keyr   r   r   r      s"   z LoaderStrategyException.__init__N)r	   r
   r   r   r   r   r   r   r   r8      s    r8   c                 C   sP   zd | j| jf}W |S  ty'   t| dd }|d u r$t| }Y |S Y |S w )N.r	   )joinr
   r	   AttributeErrorgetattrrepr)r1   cls_namer   r   r   r      s   
r   r   c              	   C   sN   t jj}z|| j}W n tft y   i }Y nw t| }|s%d| S d S )NzClass '%s' is not mapped)r   r   r   Zmanager_of_classmappers	TypeErrorNO_STATEr   )r1   r#   r?   r$   r   r   r   r      s   r   N)r    r   r4   r   r   r   r;   KeyErrorrA   ZSQLAlchemyErrorr   ZConcurrentModificationErrorr   r5   r   r   r   r   r   r2   r7   r8   r   r0   r   r   r   r   r   <module>   s*   $ 
