o
    h                     @  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 ddlmZ er^d	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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(d6d/d0Z)e
*d1d7d3d4Z+d5S )8zSQLAlchemy ORM exceptions.    )annotations)Any)Optional)Tuple)Type)TYPE_CHECKING)TypeVar   )_mapper_property_as_plain_name   )exc)util)MultipleResultsFound)NoResultFound)LoaderStrategy)MapperProperty)InstanceState_T)boundc                   @     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   f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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   )MappedAnnotationErrorzRaised when ORM annotated declarative cannot interpret the
    expression present inside of the :class:`.Mapped` construct.

    .. versionadded:: 2.0.40

    Nr   r   r   r   r   r    D   r   r    c                   @  r   )UnmappedErrorz?Base for exceptions that involve expected mappings not present.Nr   r   r   r   r   r!   M   r   r!   c                   @  r   )ObjectDereferencedErrorzPAn operation cannot complete due to an object being garbage
    collected.

    Nr   r   r   r   r   r"   Q   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.bhk3N)r   r   r   r   coder   r   r   r   r#   X   s    r#   c                   @  0   e Zd ZdZeddddd	ZdddZdS )UnmappedInstanceErrorz;An mapping operation was requested for an unknown instance.sqlalchemy.orm.baseNobjobjectmsgOptional[str]c                 C  s   t jj}|s<z|t| tt|}d||f }W n  ty;   dtt| d}t|tr9|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.Class '' is not mappedz;; was a class (%s) supplied where an instance was required?)
r   	preloadedorm_baseclass_mappertype_safe_cls_nameUnmappedClassError
isinstancer!   __init__)selfr)   r+   basenamer   r   r   r6   b   s(   
zUnmappedInstanceError.__init__returnr   c                 C     | j d | jd ffS Nr   	__class__argsr7   r   r   r   
__reduce__y      z UnmappedInstanceError.__reduce__N)r)   r*   r+   r,   r:   r   r   r   r   r   r   preload_moduler6   rA   r   r   r   r   r'   _   s
    r'   c                   @  s&   e Zd ZdZddddZdddZdS )r4   z8An mapping operation was requested for an unknown class.NclsType[_T]r+   r,   c                 C  s   |st |}t| | d S rC   )_default_unmappedr!   r6   )r7   rG   r+   r   r   r   r6      s   zUnmappedClassError.__init__r:   r   c                 C  r;   r<   r=   r@   r   r   r   rA      rB   zUnmappedClassError.__reduce__rC   )rG   rH   r+   r,   rD   )r   r   r   r   r6   rA   r   r   r   r   r4   }   s    r4   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(   NstateInstanceState[Any]r+   r,   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/   r0   	state_strsa_excInvalidRequestErrorr6   )r7   rK   r+   r8   r   r   r   r6      s   zObjectDeletedError.__init__r:   r   c                 C  r;   r<   r=   r@   r   r   r   rA      rB   zObjectDeletedError.__reduce__rC   )rK   rL   r+   r,   rD   rE   r   r   r   r   rJ      s
    rJ   c                   @  r   )UnmappedColumnErrorz5Mapping operation was requested on an unknown column.Nr   r   r   r   r   rP      r   rP   c                   @  s   e Zd ZdZdddZdS )LoaderStrategyExceptionz2A loader strategy for an attribute does not exist.applied_to_property_type	Type[Any]requesting_propertyMapperProperty[Any]
applies_to#Optional[Type[MapperProperty[Any]]]actual_strategy_typeOptional[Type[LoaderStrategy]]strategy_keyTuple[Any, ...]c              	   C  sZ   |d u rt j| d||f  d S |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".)rN   rO   r6   r   clsname_as_plain_namer
   )r7   rR   rT   rV   rX   rZ   r   r   r   r6      s$   z LoaderStrategyException.__init__N)
rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   )r   r   r   r   r6   r   r   r   r   rQ      s    rQ   rG   rS   r:   strc                 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)rG   cls_namer   r   r   r3      s   
r3   r(   r,   c              	   C  sT   t jj}z|| j}W n ttft y   i }Y nw t| }|s(d| dS d S )Nr-   r.   )	r   r/   r0   manager_of_classmappersr4   	TypeErrorNO_STATEr3   )rG   r8   re   r9   r   r   r   rI      s   
rI   N)rG   rS   r:   r]   )rG   rS   r:   r,   ),r   
__future__r   typingr   r   r   r   r   r   r   r
    r   rN   r   r   
interfacesr   r   rK   r   r   r`   KeyErrorrg   SQLAlchemyErrorr   ConcurrentModificationErrorr   ArgumentErrorr    rO   r!   r"   r#   r'   r4   rJ   rP   rQ   r3   rF   rI   r   r   r   r   <module>   sF   	$
!