summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/exc.py
Commit message (Collapse)AuthorAgeFilesLines
* Replace all http:// links to https://Federico Caselli2021-07-041-3/+3
| | | | | | Also replace http://pypi.python.org/pypi with https://pypi.org/project Change-Id: I84b5005c39969a82140706472989f2a30b0c7685
* Improve cascade backrefs warning and add `code` to deprecation warningsStephen Rosen2021-05-101-5/+21
| | | | | | | | | | | | This adds a new description to errors.rst and adds support for any SQLAlchemy warning to refer to an errors.rst code. Fixes: #6148 Closes: #6250 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6250 Pull-request-sha: dbcaeb54e31517fe88f6f8c515f1024002675f13 Change-Id: I4303c62ac9b1f13f67a34f825687014f1771c98c
* Detect non async driver on engine creationFederico Caselli2021-02-061-1/+1
| | | | | | | | | An error is raised when creating an async engine with an incompatible dbapi. Before the error was raised only when first using the engine. Change-Id: I977952b4c03ae51f568749ad744c545197bcd887 Reference: #5920
* Improve error message when await_ call errorsFederico Caselli2021-01-211-0/+9
| | | | | Fixes: #5832 Change-Id: Ia2ed8f1d1ec54e5f6e1a8f817a69446fdb3b7f6d
* Use UnsupportedCompilationError for no default compilerMike Bayer2021-01-141-3/+3
| | | | | | | | | | | | | | | Fixed issue where the stringification that is sometimes called when attempting to generate the "key" for the ``.c`` collection on a selectable would fail if the column were an unlabeled custom SQL construct using the ``sqlalchemy.ext.compiler`` extension, and did not provide a default compilation form; while this seems like an unusual case, it can get invoked for some ORM scenarios such as when the expression is used in an "order by" in combination with joined eager loading. The issue is that the lack of a default compiler function was raising :class:`.CompileError` and not :class:`.UnsupportedCompilationError`. Fixes: #5836 Change-Id: I5af243b2c70c7dcca4b212a3869c3017a50c132b
* happy new yearMike Bayer2021-01-041-1/+1
| | | | Change-Id: Ic5bb19ca8be3cb47c95a0d3315d84cb484bac47c
* Detect non compatible execution in async modeFederico Caselli2020-12-081-4/+9
| | | | | | | | | | The SQLAlchemy async mode now detects and raises an informative error when an non asyncio compatible :term:`DBAPI` is used. Using a standard ``DBAPI`` with async SQLAlchemy will cause it to block like any sync call, interrupting the executing asyncio loop. Change-Id: I9aed87dc1b0df53e8cb2109495237038aa2cb2d4
* Use preloaded for sql.util import in excMike Bayer2020-10-061-1/+3
| | | | | | | | | | | Repaired a function-level import that was not using SQLAlchemy's standard late-import system within the sqlalchemy.exc module. Moved preloaded to sqlalchemy.util.preloaded so that it does not depend on langhelpers which depends on exc. Fixes: #5632 Change-Id: I61b7ce9cd461071ce543714739f67aa5aeb47fd6
* upgrade to black 20.8b1Mike Bayer2020-09-281-1/+5
| | | | | | | It's better, the majority of these changes look more readable to me. also found some docstrings that had formatting / quoting issues. Change-Id: I582a45fde3a5648b2f36bab96bad56881321899b
* Stringify correctly for non-str exception argumentAndrzej Bartosiński2020-09-201-2/+10
| | | | | | | | | | | | | | Fixed issue where a non-string object sent to :class:`_exc.SQLAlchemyError` or a subclass, as occurs with some third party dialects, would fail to stringify correctly. Pull request courtesy Andrzej Bartosiński. Fixes: #5599 Closes: #5600 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5600 Pull-request-sha: cdccccc42a6ac8de771593a43ee8675bfd8dbeb6 Change-Id: Icd710d9015abc80f61a84893d75fbb33ee0fe46e
* Make :class:`_orm.registry` ``bind`` a private parameter.Federico Caselli2020-09-151-1/+1
| | | | | | | | | Explicitly deprecate ``bind`` from :func:`_orm.declarative_base` and :func:`_orm.as_declarative`. Some other documentation cleanup on declarative documentation. Change-Id: I3f7918d23833b2778ab7009ac5018841deb19f75
* Build out new declarative systems; deprecate mapper()Mike Bayer2020-09-101-0/+4
| | | | | | | | | | | | | The ORM Declarative system is now unified into the ORM itself, with new import spaces under ``sqlalchemy.orm`` and new kinds of mappings. Support for decorator-based mappings without using a base class, support for classical style-mapper() calls that have access to the declarative class registry for relationships, and full integration of Declarative with 3rd party class attribute systems like ``dataclasses`` and ``attrs`` is now supported. Fixes: #5508 Change-Id: I130b2b6edff6450bfe8a3e6baa099ff04b5471ff
* Emit v2.0 deprecation warning for "implicit autocommit"Gord Thompson2020-08-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | "Implicit autocommit", which is the COMMIT that occurs when a DML or DDL statement is emitted on a connection, is deprecated and won't be part of SQLAlchemy 2.0. A 2.0-style warning is emitted when autocommit takes effect, so that the calling code may be adjusted to use an explicit transaction. As part of this change, DDL methods such as :meth:`_schema.MetaData.create_all` when used against a :class:`_engine.Engine` or :class:`_engine.Connection` will run the operation in a BEGIN block if one is not started already. The MySQL and MariaDB dialects now query from the information_schema.tables system view in order to determine if a particular table exists or not. Previously, the "DESCRIBE" command was used with an exception catch to detect non-existent, which would have the undesirable effect of emitting a ROLLBACK on the connection. There appeared to be legacy encoding issues which prevented the use of "SHOW TABLES", for this, but as MySQL support is now at 5.0.2 or above due to :ticket:`4189`, the information_schema tables are now available in all cases. Fixes: #4846 Change-Id: I733a7e0e17477a63607fb9931c87c393bbd7ac57
* Add version token to error URLMike Bayer2020-06-111-1/+3
| | | | | | | | | | | | | the sqlalche.me redirector now supports the numerical version code in the URL, e.g. /13/, /14/, /20/, etc., so that we can redirect to the error codes for the appropriate version of SQLAlchemy in use without going through the catch-all "latest" link. If a particular version of the docs is no longer on the site, the redirect will revert to falling through the "latest" link (which ultimately lands on the current release version, /13/ at the time of this writing). Change-Id: I3bb463fd6fb6c8767c95a57f3699aba715a9a72d
* Update transaction / connection handlingMike Bayer2020-05-171-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | step one, do away with __connection attribute and using awkward AttributeError logic step two, move all management of "connection._transaction" into the transaction objects themselves where it's easier to follow. build MarkerTransaction that takes the role of "do-nothing block" new connection datamodel is: connection._transaction, always a root, connection._nested_transaction, always a nested. nested transactions still chain to each other as this is still sort of necessary but they consider the root transaction separately, and the marker transactions not at all. introduce new InvalidRequestError subclass PendingRollbackError. Apply to connection and session for all cases where a transaction needs to be rolled back before continuing. Within Connection, both PendingRollbackError as well as ResourceClosedError are now raised directly without being handled by handle_dbapi_error(); this removes these two exception cases from the handle_error event handler as well as from StatementError wrapping, as these two exceptions are not statement oriented and are instead programmatic issues, that the application is failing to handle database errors properly. Revise savepoints so that when a release fails, they set themselves as inactive so that their rollback() method does not throw another exception. Give savepoints another go on MySQL, can't get release working however get support for basic round trip going Fixes: #5327 Change-Id: Ia3cbbf56d4882fcc7980f90519412f1711fae74d
* Propose Result as immediate replacement for ResultProxyMike Bayer2020-05-011-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As progress is made on the _future.Result, including breaking it out such that DBAPI behaviors are local to specific implementations, it becomes apparent that the Result object is a functional superset of ResultProxy and that basic operations like fetchone(), fetchall(), and fetchmany() behave pretty much exactly the same way on the new object. Reorganize things so that ResultProxy is now referred to as LegacyCursorResult, which subclasses CursorResult that represents the DBAPI-cursor version of Result, making use of a multiple inheritance pattern so that the functionality of Result is also available in non-DBAPI contexts, as will be necessary for some ORM patterns. Additionally propose the composition system for Result that will form the basis for ORM-alternative result systems such as horizontal sharding and dogpile cache. As ORM results will soon be coming directly from instances of Result, these extensions will instead build their own ResultFetchStrategies that perform the special steps to create composed or cached result sets. Also considering at the moment not emitting deprecation warnings for fetchXYZ() methods; the immediate issue is Keystone tests are calling upon it, but as the implementations here are proving to be not in any kind of conflict with how Result works, there's not too much issue leaving them around and deprecating at some later point. References: #5087 References: #4395 Fixes: #4959 Change-Id: I8091919d45421e3f53029b8660427f844fee0228
* Run search and replace of symbolic module namesMike Bayer2020-04-141-6/+8
| | | | | | | | Replaces a wide array of Sphinx-relative doc references with an abbreviated absolute form now supported by zzzeeksphinx. Change-Id: I94bffcc3f37885ffdde6238767224296339698a2
* Remove code deprecated before version 1.1Federico Caselli2020-04-091-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Remove deprecated method ``get_primary_keys` in the :class:`.Dialect` and :class:`.Inspector` classes. - Remove deprecated event ``dbapi_error`` and the method ``ConnectionEvents.dbapi_error`. - Remove support for deprecated engine URLs of the form ``postgres://``. - Remove deprecated dialect ``mysql+gaerdbms``. - Remove deprecated parameter ``quoting`` from :class:`.mysql.ENUM` and :class:`.mysql.SET` in the ``mysql`` dialect. - Remove deprecated function ``comparable_property``. and function ``comparable_using`` in the declarative extension. - Remove deprecated function ``compile_mappers``. - Remove deprecated method ``collection.linker``. - Remove deprecated method ``Session.prune`` and parameter ``Session.weak_identity_map``. This change also removes the class ``StrongInstanceDict``. - Remove deprecated parameter ``mapper.order_by``. - Remove deprecated parameter ``Session._enable_transaction_accounting`. - Remove deprecated parameter ``Session.is_modified.passive``. - Remove deprecated class ``Binary``. Please use :class:`.LargeBinary`. - Remove deprecated methods ``Compiled.compile``, ``ClauseElement.__and__`` and ``ClauseElement.__or__`` and attribute ``Over.func``. - Remove deprecated ``FromClause.count`` method. - Remove deprecated parameter ``Table.useexisting``. - Remove deprecated parameters ``text.bindparams`` and ``text.typemap``. - Remove boolean support for the ``passive`` parameter in ``get_history``. - Remove deprecated ``adapt_operator`` in ``UserDefinedType.Comparator``. Fixes: #4643 Change-Id: Idcd390c77bf7b0e9957907716993bdaa3f1a1763
* Create initial future package, RemovedIn20WarningMike Bayer2020-02-121-2/+15
| | | | | | | | | | | | | | | | | Reorganization of Select() is the first major element of the 2.0 restructuring. In order to start this we need to first create the new Select constructor and apply legacy elements to the old one. This in turn necessitates starting up the RemovedIn20Warning concept which itself need to refer to "sqlalchemy.future", so begin to establish this basic framework. Additionally, update the DML constructors with the newer no-keyword style. Remove the use of the "pending deprecation" and fix Query.add_column() deprecation which was not acting as deprecated. Fixes: #4845 Fixes: #4648 Change-Id: I0c7a22b2841a985e1c379a0bb6c94089aae6264c
* happy new yearMike Bayer2020-01-011-1/+1
| | | | Change-Id: I08440dc25e40ea1ccea1778f6ee9e28a00808235
* pass executemany context to _repr_paramsMike Bayer2019-10-111-1/+15
| | | | | | | | | | | | | | | | | | Fixed bug where parameter repr as used in logging and error reporting needs additional context in order to distinguish between a list of parameters for a single statement and a list of parameter lists, as the "list of lists" structure could also indicate a single parameter list where the first parameter itself is a list, such as for an array parameter. The engine/connection now passes in an additional boolean indicating how the parameters should be considered. The only SQLAlchemy backend that expects arrays as parameters is that of psycopg2 which uses pyformat parameters, so this issue has not been too apparent, however as other drivers that use positional gain more features it is important that this be supported. It also eliminates the need for the parameter repr function to guess based on the parameter structure passed. Fixes: #4902 Change-Id: I086246ee0eb51484adbefd83e07295fa56576c5f
* Run row value processors up frontMike Bayer2019-10-011-1/+1
| | | | | | | | | | | | as part of a larger series of changes to generalize row-tuples, RowProxy becomes plain Row and is no longer a "proxy"; the DBAPI row is now copied directly into the Row when constructed, result handling occurs at once. Subsequent changes will break out Row into a new version that behaves fully a tuple. Change-Id: I2ffa156afce5d21c38f28e54c3a531f361345dd5
* Add hide_parameters flag to create_engineMike Bayer2019-08-221-6/+42
| | | | | | | | | Added new parameter :paramref:`.create_engine.hide_parameters` which when set to True will cause SQL parameters to no longer be logged, nor rendered in the string representation of a :class:`.StatementError` object. Fixes: #4815 Change-Id: Ib87f868b6936cf6b42b192644e9d732ec24266c2
* Enhance documentation for string compilation use casesMike Bayer2019-04-041-0/+7
| | | | | | | | | | - Add a web link for UnsupportedCompilationError - Add new section to errors.rst - add more detail and cross-linking to the FAQ - include security caveats for parameter rendering Fixes: #4595 Change-Id: I31ea57c18d65770cd2a51276bbe2847a9eb72bba
* Include newlines in StatementError formattingNate Clark2019-02-201-3/+9
| | | | | | | | | | | | | | | | Revised the formatting for :class:`.StatementError` when stringified. Each error detail is broken up over multiple newlines instead of spaced out on a single line. Additionally, the SQL representation now stringifies the SQL statement rather than using ``repr()``, so that newlines are rendered as is. Pull request courtesy Nate Clark. Fixes: #4500 Closes: #4501 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4501 Pull-request-sha: 60cc0ee68dc96b8f483a60d37bcb26b6c6d53efe Change-Id: I79d8418b7495e5691c9a56f41e79495c26a967ff
* Fix many spell glitchesLele Gaifax2019-01-251-1/+1
| | | | | | | | | | | | This affects mostly docstrings, except in orm/events.py::dispose_collection() where one parameter gets renamed: given that the method is empty, it seemed reasonable to me to fix that too. Closes: #4440 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4440 Pull-request-sha: 779ed75acb6142e1f1daac467b5b14134529bb4b Change-Id: Ic0553fe97853054b09c2453af76d96363de6eb0e
* Remove version directives for 0.6, 0.7, 0.8Mike Bayer2019-01-151-3/+0
| | | | | | | | | - fix a few "seealso"s - ComparableProprerty's "superseded in 0.7" becomes deprecated in 0.7 Backport to currently maintained doc versions 1.2, 1.1 Change-Id: Ib1fcb2df8673dbe5c4ffc47f3896a60d1dfcb4b2
* happy new yearMike Bayer2019-01-111-1/+1
| | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Leave bytestring exception messages as bytestringsMike Bayer2019-01-101-10/+33
| | | | | | | | | | | | | | | | | Fixed a regression introduced in version 1.2 where a refactor of the :class:`.SQLAlchemyError` base exception class introduced an inappropriate coercion of a plain string message into Unicode under python 2k, which is not handled by the Python interpreter for characters outside of the platform's encoding (typically ascii). The :class:`.SQLAlchemyError` class now passes a bytestring through under Py2K for ``__str__()`` as is the behavior of exception objects in general under Py2K, does a safe coercion to unicode utf-8 with backslash fallback for ``__unicode__()``. For Py3K the message is typically unicode already, but if not is again safe-coerced with utf-8 with backslash fallback for the ``__str__()`` method. Fixes: #4429 Change-Id: I2289da3f2c45c7d0041fa43d838958f7614defc3
* Post black reformattingMike Bayer2019-01-061-1/+1
| | | | | | | | | | | | | Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
* Run black -l 79 against all source filesMike Bayer2019-01-061-43/+78
| | | | | | | | | | | | | | This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Implement an error lookupMike Bayer2017-12-271-12/+79
| | | | | | | | Add codes to commonly raised error messages and classes that link back to fixed documentation sections giving background on these messages. Change-Id: I78d0660add7026bb662e20305a59283b20616954
* Allow metadata.reflect() to recover from unreflectable tablesMike Bayer2017-05-221-0/+8
| | | | | | | | | | | | | Added support for views that are unreflectable due to stale table definitions, when calling :meth:`.MetaData.reflect`; a warning is emitted for the table that cannot respond to ``DESCRIBE`` but the operation succeeds. The MySQL dialect now raises UnreflectableTableError which is in turn caught by MetaData.reflect(). Reflecting the view standalone raises this error directly. Change-Id: Id8005219d8e073c154cc84a873df911b4a6cf4d6 Fixes: #3871
* Integrate "pre-ping" into connection pool.Mike Bayer2017-03-201-0/+17
| | | | | | | | | | | | | | | Added native "pessimistic disconnection" handling to the :class:`.Pool` object. The new parameter :paramref:`.Pool.pre_ping`, available from the engine as :paramref:`.create_engine.pool_pre_ping`, applies an efficient form of the "pre-ping" recipe featured in the pooling documentation, which upon each connection check out, emits a simple statement, typically "SELECT 1", to test the connection for liveness. If the existing connection is no longer able to respond to commands, the connection is transparently recycled, and all other connections made prior to the current timestamp are invalidated. Change-Id: I89700d0075e60abd2250e54b9bd14daf03c71c00 Fixes: #3919
* update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* Check for supports_execution at ClauseElement baseMike Bayer2016-08-311-0/+14
| | | | | | | | | | Raise a more descriptive exception / message when ClauseElement or non-SQLAlchemy objects that are not "executable" are erroneously passed to ``.execute()``; a new exception ObjectNotExecutableError is raised consistently in all cases. Change-Id: I2dd393121e2c7e5b6b9e40286a2f25670876e8e4 Fixes: #3786
* - happy new yearMike Bayer2016-01-291-1/+1
|
* - Added support for the case of the misbehaving DBAPI that hasMike Bayer2015-05-151-3/+5
| | | | | | | | | | | pep-249 exception names linked to exception classes of an entirely different name, preventing SQLAlchemy's own exception wrapping from wrapping the error appropriately. The SQLAlchemy dialect in use needs to implement a new accessor :attr:`.DefaultDialect.dbapi_exception_translation_map` to support this feature; this is implemented now for the py-postgresql dialect. fixes #3421
* - tweaks regarding the use_alter updateMike Bayer2015-03-131-2/+1
|
* - copyright 2015Mike Bayer2015-03-101-1/+1
|
* - remove the "edges" from the message here. It's illegibleMike Bayer2015-01-011-1/+1
|
* - Exception messages have been spiffed up a bit. The SQL statementMike Bayer2014-10-171-9/+12
| | | | | | | | | | | and parameters are not displayed if None, reducing confusion for error messages that weren't related to a statement. The full module and classname for the DBAPI-level exception is displayed, making it clear that this is a wrapped DBAPI exception. The statement and parameters themselves are bounded within a bracketed sections to better isolate them from the error message and from each other. fixes #3172
* - the test_except test was doing an unnecessary workaround of some kind,Mike Bayer2014-10-121-7/+3
| | | | take that out, restore the better exception logic in exc
* - roll back part of pr 140 to get exception wrapping working againMike Bayer2014-10-121-3/+7
|
* cleanup exception handling - use new exception hierarchy (since python 2.5)pr/140ndparker2014-10-021-3/+3
|
* - The exception wrapping system for DBAPI errors can now accommodateMike Bayer2014-07-291-3/+6
| | | | | | | | non-standard DBAPI exceptions, such as the psycopg2 TransactionRollbackError. These exceptions will now be raised using the closest available subclass in ``sqlalchemy.exc``, in the case of TransactionRollbackError, ``sqlalchemy.exc.OperationalError``. fixes #3075
* PEP8 style fixesBrian Jarrett2014-07-131-18/+21
|
* - break up the <authors> copyright comment as part of a passMike Bayer2014-07-091-1/+2
| | | | to get all flake8 passing
* - implement kwarg validation and type system for dialect-specificMike Bayer2014-01-181-0/+3
| | | | | arguments; [ticket:2866] - add dialect specific kwarg functionality to ForeignKeyConstraint, ForeignKey