exc.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. # exc.py
  2. # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: https://www.opensource.org/licenses/mit-license.php
  7. """Exceptions used with SQLAlchemy.
  8. The base exception class is :exc:`.SQLAlchemyError`. Exceptions which are
  9. raised as a result of DBAPI exceptions are all subclasses of
  10. :exc:`.DBAPIError`.
  11. """
  12. from __future__ import annotations
  13. import typing
  14. from typing import Any
  15. from typing import List
  16. from typing import Optional
  17. from typing import overload
  18. from typing import Tuple
  19. from typing import Type
  20. from typing import Union
  21. from .util import compat
  22. from .util import preloaded as _preloaded
  23. if typing.TYPE_CHECKING:
  24. from .engine.interfaces import _AnyExecuteParams
  25. from .engine.interfaces import Dialect
  26. from .sql.compiler import Compiled
  27. from .sql.compiler import TypeCompiler
  28. from .sql.elements import ClauseElement
  29. if typing.TYPE_CHECKING:
  30. _version_token: str
  31. else:
  32. # set by __init__.py
  33. _version_token = None
  34. class HasDescriptionCode:
  35. """helper which adds 'code' as an attribute and '_code_str' as a method"""
  36. code: Optional[str] = None
  37. def __init__(self, *arg: Any, **kw: Any):
  38. code = kw.pop("code", None)
  39. if code is not None:
  40. self.code = code
  41. super().__init__(*arg, **kw)
  42. _what_are_we = "error"
  43. def _code_str(self) -> str:
  44. if not self.code:
  45. return ""
  46. else:
  47. return (
  48. f"(Background on this {self._what_are_we} at: "
  49. f"https://sqlalche.me/e/{_version_token}/{self.code})"
  50. )
  51. def __str__(self) -> str:
  52. message = super().__str__()
  53. if self.code:
  54. message = "%s %s" % (message, self._code_str())
  55. return message
  56. class SQLAlchemyError(HasDescriptionCode, Exception):
  57. """Generic error class."""
  58. def _message(self) -> str:
  59. # rules:
  60. #
  61. # 1. single arg string will usually be a unicode
  62. # object, but since __str__() must return unicode, check for
  63. # bytestring just in case
  64. #
  65. # 2. for multiple self.args, this is not a case in current
  66. # SQLAlchemy though this is happening in at least one known external
  67. # library, call str() which does a repr().
  68. #
  69. text: str
  70. if len(self.args) == 1:
  71. arg_text = self.args[0]
  72. if isinstance(arg_text, bytes):
  73. text = compat.decode_backslashreplace(arg_text, "utf-8")
  74. # This is for when the argument is not a string of any sort.
  75. # Otherwise, converting this exception to string would fail for
  76. # non-string arguments.
  77. else:
  78. text = str(arg_text)
  79. return text
  80. else:
  81. # this is not a normal case within SQLAlchemy but is here for
  82. # compatibility with Exception.args - the str() comes out as
  83. # a repr() of the tuple
  84. return str(self.args)
  85. def _sql_message(self) -> str:
  86. message = self._message()
  87. if self.code:
  88. message = "%s %s" % (message, self._code_str())
  89. return message
  90. def __str__(self) -> str:
  91. return self._sql_message()
  92. class ArgumentError(SQLAlchemyError):
  93. """Raised when an invalid or conflicting function argument is supplied.
  94. This error generally corresponds to construction time state errors.
  95. """
  96. class DuplicateColumnError(ArgumentError):
  97. """a Column is being added to a Table that would replace another
  98. Column, without appropriate parameters to allow this in place.
  99. .. versionadded:: 2.0.0b4
  100. """
  101. class ObjectNotExecutableError(ArgumentError):
  102. """Raised when an object is passed to .execute() that can't be
  103. executed as SQL.
  104. """
  105. def __init__(self, target: Any):
  106. super().__init__("Not an executable object: %r" % target)
  107. self.target = target
  108. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  109. return self.__class__, (self.target,)
  110. class NoSuchModuleError(ArgumentError):
  111. """Raised when a dynamically-loaded module (usually a database dialect)
  112. of a particular name cannot be located."""
  113. class NoForeignKeysError(ArgumentError):
  114. """Raised when no foreign keys can be located between two selectables
  115. during a join."""
  116. class AmbiguousForeignKeysError(ArgumentError):
  117. """Raised when more than one foreign key matching can be located
  118. between two selectables during a join."""
  119. class ConstraintColumnNotFoundError(ArgumentError):
  120. """raised when a constraint refers to a string column name that
  121. is not present in the table being constrained.
  122. .. versionadded:: 2.0
  123. """
  124. class CircularDependencyError(SQLAlchemyError):
  125. """Raised by topological sorts when a circular dependency is detected.
  126. There are two scenarios where this error occurs:
  127. * In a Session flush operation, if two objects are mutually dependent
  128. on each other, they can not be inserted or deleted via INSERT or
  129. DELETE statements alone; an UPDATE will be needed to post-associate
  130. or pre-deassociate one of the foreign key constrained values.
  131. The ``post_update`` flag described at :ref:`post_update` can resolve
  132. this cycle.
  133. * In a :attr:`_schema.MetaData.sorted_tables` operation, two
  134. :class:`_schema.ForeignKey`
  135. or :class:`_schema.ForeignKeyConstraint` objects mutually refer to each
  136. other. Apply the ``use_alter=True`` flag to one or both,
  137. see :ref:`use_alter`.
  138. """
  139. def __init__(
  140. self,
  141. message: str,
  142. cycles: Any,
  143. edges: Any,
  144. msg: Optional[str] = None,
  145. code: Optional[str] = None,
  146. ):
  147. if msg is None:
  148. message += " (%s)" % ", ".join(repr(s) for s in cycles)
  149. else:
  150. message = msg
  151. SQLAlchemyError.__init__(self, message, code=code)
  152. self.cycles = cycles
  153. self.edges = edges
  154. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  155. return (
  156. self.__class__,
  157. (None, self.cycles, self.edges, self.args[0]),
  158. {"code": self.code} if self.code is not None else {},
  159. )
  160. class CompileError(SQLAlchemyError):
  161. """Raised when an error occurs during SQL compilation"""
  162. class UnsupportedCompilationError(CompileError):
  163. """Raised when an operation is not supported by the given compiler.
  164. .. seealso::
  165. :ref:`faq_sql_expression_string`
  166. :ref:`error_l7de`
  167. """
  168. code = "l7de"
  169. def __init__(
  170. self,
  171. compiler: Union[Compiled, TypeCompiler],
  172. element_type: Type[ClauseElement],
  173. message: Optional[str] = None,
  174. ):
  175. super().__init__(
  176. "Compiler %r can't render element of type %s%s"
  177. % (compiler, element_type, ": %s" % message if message else "")
  178. )
  179. self.compiler = compiler
  180. self.element_type = element_type
  181. self.message = message
  182. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  183. return self.__class__, (self.compiler, self.element_type, self.message)
  184. class IdentifierError(SQLAlchemyError):
  185. """Raised when a schema name is beyond the max character limit"""
  186. class DisconnectionError(SQLAlchemyError):
  187. """A disconnect is detected on a raw DB-API connection.
  188. This error is raised and consumed internally by a connection pool. It can
  189. be raised by the :meth:`_events.PoolEvents.checkout`
  190. event so that the host pool
  191. forces a retry; the exception will be caught three times in a row before
  192. the pool gives up and raises :class:`~sqlalchemy.exc.InvalidRequestError`
  193. regarding the connection attempt.
  194. """
  195. invalidate_pool: bool = False
  196. class InvalidatePoolError(DisconnectionError):
  197. """Raised when the connection pool should invalidate all stale connections.
  198. A subclass of :class:`_exc.DisconnectionError` that indicates that the
  199. disconnect situation encountered on the connection probably means the
  200. entire pool should be invalidated, as the database has been restarted.
  201. This exception will be handled otherwise the same way as
  202. :class:`_exc.DisconnectionError`, allowing three attempts to reconnect
  203. before giving up.
  204. .. versionadded:: 1.2
  205. """
  206. invalidate_pool: bool = True
  207. class TimeoutError(SQLAlchemyError): # noqa
  208. """Raised when a connection pool times out on getting a connection."""
  209. class InvalidRequestError(SQLAlchemyError):
  210. """SQLAlchemy was asked to do something it can't do.
  211. This error generally corresponds to runtime state errors.
  212. """
  213. class IllegalStateChangeError(InvalidRequestError):
  214. """An object that tracks state encountered an illegal state change
  215. of some kind.
  216. .. versionadded:: 2.0
  217. """
  218. class NoInspectionAvailable(InvalidRequestError):
  219. """A subject passed to :func:`sqlalchemy.inspection.inspect` produced
  220. no context for inspection."""
  221. class PendingRollbackError(InvalidRequestError):
  222. """A transaction has failed and needs to be rolled back before
  223. continuing.
  224. .. versionadded:: 1.4
  225. """
  226. class ResourceClosedError(InvalidRequestError):
  227. """An operation was requested from a connection, cursor, or other
  228. object that's in a closed state."""
  229. class NoSuchColumnError(InvalidRequestError, KeyError):
  230. """A nonexistent column is requested from a ``Row``."""
  231. class NoResultFound(InvalidRequestError):
  232. """A database result was required but none was found.
  233. .. versionchanged:: 1.4 This exception is now part of the
  234. ``sqlalchemy.exc`` module in Core, moved from the ORM. The symbol
  235. remains importable from ``sqlalchemy.orm.exc``.
  236. """
  237. class MultipleResultsFound(InvalidRequestError):
  238. """A single database result was required but more than one were found.
  239. .. versionchanged:: 1.4 This exception is now part of the
  240. ``sqlalchemy.exc`` module in Core, moved from the ORM. The symbol
  241. remains importable from ``sqlalchemy.orm.exc``.
  242. """
  243. class NoReferenceError(InvalidRequestError):
  244. """Raised by ``ForeignKey`` to indicate a reference cannot be resolved."""
  245. table_name: str
  246. class AwaitRequired(InvalidRequestError):
  247. """Error raised by the async greenlet spawn if no async operation
  248. was awaited when it required one.
  249. """
  250. code = "xd1r"
  251. class MissingGreenlet(InvalidRequestError):
  252. r"""Error raised by the async greenlet await\_ if called while not inside
  253. the greenlet spawn context.
  254. """
  255. code = "xd2s"
  256. class NoReferencedTableError(NoReferenceError):
  257. """Raised by ``ForeignKey`` when the referred ``Table`` cannot be
  258. located.
  259. """
  260. def __init__(self, message: str, tname: str):
  261. NoReferenceError.__init__(self, message)
  262. self.table_name = tname
  263. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  264. return self.__class__, (self.args[0], self.table_name)
  265. class NoReferencedColumnError(NoReferenceError):
  266. """Raised by ``ForeignKey`` when the referred ``Column`` cannot be
  267. located.
  268. """
  269. def __init__(self, message: str, tname: str, cname: str):
  270. NoReferenceError.__init__(self, message)
  271. self.table_name = tname
  272. self.column_name = cname
  273. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  274. return (
  275. self.__class__,
  276. (self.args[0], self.table_name, self.column_name),
  277. )
  278. class NoSuchTableError(InvalidRequestError):
  279. """Table does not exist or is not visible to a connection."""
  280. class UnreflectableTableError(InvalidRequestError):
  281. """Table exists but can't be reflected for some reason.
  282. .. versionadded:: 1.2
  283. """
  284. class UnboundExecutionError(InvalidRequestError):
  285. """SQL was attempted without a database connection to execute it on."""
  286. class DontWrapMixin:
  287. """A mixin class which, when applied to a user-defined Exception class,
  288. will not be wrapped inside of :exc:`.StatementError` if the error is
  289. emitted within the process of executing a statement.
  290. E.g.::
  291. from sqlalchemy.exc import DontWrapMixin
  292. class MyCustomException(Exception, DontWrapMixin):
  293. pass
  294. class MySpecialType(TypeDecorator):
  295. impl = String
  296. def process_bind_param(self, value, dialect):
  297. if value == "invalid":
  298. raise MyCustomException("invalid!")
  299. """
  300. class StatementError(SQLAlchemyError):
  301. """An error occurred during execution of a SQL statement.
  302. :class:`StatementError` wraps the exception raised
  303. during execution, and features :attr:`.statement`
  304. and :attr:`.params` attributes which supply context regarding
  305. the specifics of the statement which had an issue.
  306. The wrapped exception object is available in
  307. the :attr:`.orig` attribute.
  308. """
  309. statement: Optional[str] = None
  310. """The string SQL statement being invoked when this exception occurred."""
  311. params: Optional[_AnyExecuteParams] = None
  312. """The parameter list being used when this exception occurred."""
  313. orig: Optional[BaseException] = None
  314. """The original exception that was thrown.
  315. """
  316. ismulti: Optional[bool] = None
  317. """multi parameter passed to repr_params(). None is meaningful."""
  318. connection_invalidated: bool = False
  319. def __init__(
  320. self,
  321. message: str,
  322. statement: Optional[str],
  323. params: Optional[_AnyExecuteParams],
  324. orig: Optional[BaseException],
  325. hide_parameters: bool = False,
  326. code: Optional[str] = None,
  327. ismulti: Optional[bool] = None,
  328. ):
  329. SQLAlchemyError.__init__(self, message, code=code)
  330. self.statement = statement
  331. self.params = params
  332. self.orig = orig
  333. self.ismulti = ismulti
  334. self.hide_parameters = hide_parameters
  335. self.detail: List[str] = []
  336. def add_detail(self, msg: str) -> None:
  337. self.detail.append(msg)
  338. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  339. return (
  340. self.__class__,
  341. (
  342. self.args[0],
  343. self.statement,
  344. self.params,
  345. self.orig,
  346. self.hide_parameters,
  347. self.__dict__.get("code"),
  348. self.ismulti,
  349. ),
  350. {"detail": self.detail},
  351. )
  352. @_preloaded.preload_module("sqlalchemy.sql.util")
  353. def _sql_message(self) -> str:
  354. util = _preloaded.sql_util
  355. details = [self._message()]
  356. if self.statement:
  357. stmt_detail = "[SQL: %s]" % self.statement
  358. details.append(stmt_detail)
  359. if self.params:
  360. if self.hide_parameters:
  361. details.append(
  362. "[SQL parameters hidden due to hide_parameters=True]"
  363. )
  364. else:
  365. params_repr = util._repr_params(
  366. self.params, 10, ismulti=self.ismulti
  367. )
  368. details.append("[parameters: %r]" % params_repr)
  369. code_str = self._code_str()
  370. if code_str:
  371. details.append(code_str)
  372. return "\n".join(["(%s)" % det for det in self.detail] + details)
  373. class DBAPIError(StatementError):
  374. """Raised when the execution of a database operation fails.
  375. Wraps exceptions raised by the DB-API underlying the
  376. database operation. Driver-specific implementations of the standard
  377. DB-API exception types are wrapped by matching sub-types of SQLAlchemy's
  378. :class:`DBAPIError` when possible. DB-API's ``Error`` type maps to
  379. :class:`DBAPIError` in SQLAlchemy, otherwise the names are identical. Note
  380. that there is no guarantee that different DB-API implementations will
  381. raise the same exception type for any given error condition.
  382. :class:`DBAPIError` features :attr:`~.StatementError.statement`
  383. and :attr:`~.StatementError.params` attributes which supply context
  384. regarding the specifics of the statement which had an issue, for the
  385. typical case when the error was raised within the context of
  386. emitting a SQL statement.
  387. The wrapped exception object is available in the
  388. :attr:`~.StatementError.orig` attribute. Its type and properties are
  389. DB-API implementation specific.
  390. """
  391. code = "dbapi"
  392. @overload
  393. @classmethod
  394. def instance(
  395. cls,
  396. statement: Optional[str],
  397. params: Optional[_AnyExecuteParams],
  398. orig: Exception,
  399. dbapi_base_err: Type[Exception],
  400. hide_parameters: bool = False,
  401. connection_invalidated: bool = False,
  402. dialect: Optional[Dialect] = None,
  403. ismulti: Optional[bool] = None,
  404. ) -> StatementError: ...
  405. @overload
  406. @classmethod
  407. def instance(
  408. cls,
  409. statement: Optional[str],
  410. params: Optional[_AnyExecuteParams],
  411. orig: DontWrapMixin,
  412. dbapi_base_err: Type[Exception],
  413. hide_parameters: bool = False,
  414. connection_invalidated: bool = False,
  415. dialect: Optional[Dialect] = None,
  416. ismulti: Optional[bool] = None,
  417. ) -> DontWrapMixin: ...
  418. @overload
  419. @classmethod
  420. def instance(
  421. cls,
  422. statement: Optional[str],
  423. params: Optional[_AnyExecuteParams],
  424. orig: BaseException,
  425. dbapi_base_err: Type[Exception],
  426. hide_parameters: bool = False,
  427. connection_invalidated: bool = False,
  428. dialect: Optional[Dialect] = None,
  429. ismulti: Optional[bool] = None,
  430. ) -> BaseException: ...
  431. @classmethod
  432. def instance(
  433. cls,
  434. statement: Optional[str],
  435. params: Optional[_AnyExecuteParams],
  436. orig: Union[BaseException, DontWrapMixin],
  437. dbapi_base_err: Type[Exception],
  438. hide_parameters: bool = False,
  439. connection_invalidated: bool = False,
  440. dialect: Optional[Dialect] = None,
  441. ismulti: Optional[bool] = None,
  442. ) -> Union[BaseException, DontWrapMixin]:
  443. # Don't ever wrap these, just return them directly as if
  444. # DBAPIError didn't exist.
  445. if (
  446. isinstance(orig, BaseException) and not isinstance(orig, Exception)
  447. ) or isinstance(orig, DontWrapMixin):
  448. return orig
  449. if orig is not None:
  450. # not a DBAPI error, statement is present.
  451. # raise a StatementError
  452. if isinstance(orig, SQLAlchemyError) and statement:
  453. return StatementError(
  454. "(%s.%s) %s"
  455. % (
  456. orig.__class__.__module__,
  457. orig.__class__.__name__,
  458. orig.args[0],
  459. ),
  460. statement,
  461. params,
  462. orig,
  463. hide_parameters=hide_parameters,
  464. code=orig.code,
  465. ismulti=ismulti,
  466. )
  467. elif not isinstance(orig, dbapi_base_err) and statement:
  468. return StatementError(
  469. "(%s.%s) %s"
  470. % (
  471. orig.__class__.__module__,
  472. orig.__class__.__name__,
  473. orig,
  474. ),
  475. statement,
  476. params,
  477. orig,
  478. hide_parameters=hide_parameters,
  479. ismulti=ismulti,
  480. )
  481. glob = globals()
  482. for super_ in orig.__class__.__mro__:
  483. name = super_.__name__
  484. if dialect:
  485. name = dialect.dbapi_exception_translation_map.get(
  486. name, name
  487. )
  488. if name in glob and issubclass(glob[name], DBAPIError):
  489. cls = glob[name]
  490. break
  491. return cls(
  492. statement,
  493. params,
  494. orig,
  495. connection_invalidated=connection_invalidated,
  496. hide_parameters=hide_parameters,
  497. code=cls.code,
  498. ismulti=ismulti,
  499. )
  500. def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
  501. return (
  502. self.__class__,
  503. (
  504. self.statement,
  505. self.params,
  506. self.orig,
  507. self.hide_parameters,
  508. self.connection_invalidated,
  509. self.__dict__.get("code"),
  510. self.ismulti,
  511. ),
  512. {"detail": self.detail},
  513. )
  514. def __init__(
  515. self,
  516. statement: Optional[str],
  517. params: Optional[_AnyExecuteParams],
  518. orig: BaseException,
  519. hide_parameters: bool = False,
  520. connection_invalidated: bool = False,
  521. code: Optional[str] = None,
  522. ismulti: Optional[bool] = None,
  523. ):
  524. try:
  525. text = str(orig)
  526. except Exception as e:
  527. text = "Error in str() of DB-API-generated exception: " + str(e)
  528. StatementError.__init__(
  529. self,
  530. "(%s.%s) %s"
  531. % (orig.__class__.__module__, orig.__class__.__name__, text),
  532. statement,
  533. params,
  534. orig,
  535. hide_parameters,
  536. code=code,
  537. ismulti=ismulti,
  538. )
  539. self.connection_invalidated = connection_invalidated
  540. class InterfaceError(DBAPIError):
  541. """Wraps a DB-API InterfaceError."""
  542. code = "rvf5"
  543. class DatabaseError(DBAPIError):
  544. """Wraps a DB-API DatabaseError."""
  545. code = "4xp6"
  546. class DataError(DatabaseError):
  547. """Wraps a DB-API DataError."""
  548. code = "9h9h"
  549. class OperationalError(DatabaseError):
  550. """Wraps a DB-API OperationalError."""
  551. code = "e3q8"
  552. class IntegrityError(DatabaseError):
  553. """Wraps a DB-API IntegrityError."""
  554. code = "gkpj"
  555. class InternalError(DatabaseError):
  556. """Wraps a DB-API InternalError."""
  557. code = "2j85"
  558. class ProgrammingError(DatabaseError):
  559. """Wraps a DB-API ProgrammingError."""
  560. code = "f405"
  561. class NotSupportedError(DatabaseError):
  562. """Wraps a DB-API NotSupportedError."""
  563. code = "tw8g"
  564. # Warnings
  565. class SATestSuiteWarning(Warning):
  566. """warning for a condition detected during tests that is non-fatal
  567. Currently outside of SAWarning so that we can work around tools like
  568. Alembic doing the wrong thing with warnings.
  569. """
  570. class SADeprecationWarning(HasDescriptionCode, DeprecationWarning):
  571. """Issued for usage of deprecated APIs."""
  572. deprecated_since: Optional[str] = None
  573. "Indicates the version that started raising this deprecation warning"
  574. class Base20DeprecationWarning(SADeprecationWarning):
  575. """Issued for usage of APIs specifically deprecated or legacy in
  576. SQLAlchemy 2.0.
  577. .. seealso::
  578. :ref:`error_b8d9`.
  579. :ref:`deprecation_20_mode`
  580. """
  581. deprecated_since: Optional[str] = "1.4"
  582. "Indicates the version that started raising this deprecation warning"
  583. def __str__(self) -> str:
  584. return (
  585. super().__str__()
  586. + " (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)"
  587. )
  588. class LegacyAPIWarning(Base20DeprecationWarning):
  589. """indicates an API that is in 'legacy' status, a long term deprecation."""
  590. class MovedIn20Warning(Base20DeprecationWarning):
  591. """Subtype of RemovedIn20Warning to indicate an API that moved only."""
  592. class SAPendingDeprecationWarning(PendingDeprecationWarning):
  593. """A similar warning as :class:`_exc.SADeprecationWarning`, this warning
  594. is not used in modern versions of SQLAlchemy.
  595. """
  596. deprecated_since: Optional[str] = None
  597. "Indicates the version that started raising this deprecation warning"
  598. class SAWarning(HasDescriptionCode, RuntimeWarning):
  599. """Issued at runtime."""
  600. _what_are_we = "warning"