Commit Graph

672 Commits

Author SHA1 Message Date
Mike Bayer befe7ffcb8 use ..deprecated directive w/ version in all cases
These changes should be ported from 1.3 back to 1.0 or
possibly 0.9 to the extent they are relevant in each
version. In 1.3 we hope to turn all deprecation documentation
into warnings.

(cherry picked from commit 77e9534673d58f2f4c33d16c0ed4e8671cea48b6)
(cherry picked from commit dcfe5a3f8929a11fd8d89b3b34449e1894bb2a3b)

Change-Id: I205186cde161af9389af513a425c62ce90dd54d8
2019-01-12 18:14:21 -05:00
Mike Bayer 6c6f865541 Ensure weakref finalize_fairy operates upon the current connection
Fixed a fairly serious connection pool bug where a connection that is
acquired after being refreshed as a result of a user-defined
:class:`.DisconnectionError` or due to the 1.2-released "pre_ping" feature
would not be correctly reset if the connection were returned to the pool by
weakref cleanup (e.g. the front-facing object is garbage collected); the
weakref would still refer to the previously invalidated DBAPI connection
which would have the reset operation erroneously called upon it instead.
This would lead to stack traces in the logs and a connection being checked
into the pool without being reset, which can cause locking issues.

Change-Id: Iabd9f3a63a1d0207d0de0054a6ced3560818cf9c
Fixes: #4184
(cherry picked from commit ab1f524c355c0bbac68485a60cb99e7a9d0f944a)
2018-02-08 14:56:19 -05:00
Mike Bayer 917a971764 Support mariadb 10.2
Fixed issue where CURRENT_TIMESTAMP would not reflect correctly
in the MariaDB 10.2 series due to a syntax change, where the function
is now represented as ``current_timestamp()``.

Fixes: #4096

MariaDB 10.2 now supports CHECK constraints (warning: use version 10.2.9
or greater due to upstream issues noted in 🎫`4097`).  Reflection
now takes these CHECK constraints into account when they are present in
the ``SHOW CREATE TABLE`` output.

Fixes: #4098

Change-Id: I8666d61814e8145ca12cbecad94019b44af868e3
(cherry picked from commit 29b752f8b2)
2017-09-29 13:21:16 -04:00
Mike Bayer 53175850bf First level repair for cx_Oracle 6.0 test regressions
Fixed more regressions caused by cx_Oracle 6.0; at the moment, the only
behavioral change for users is disconnect detection now detects for
cx_Oracle.DatabaseError in addition to cx_Oracle.InterfaceError, as
this behavior seems to have changed.   Other issues regarding numeric
precision and uncloseable connections are pending with the upstream
cx_Oracle issue tracker.

Change-Id: Id61f1e33b21c155a598396340dfdecd28ff4066b
Fixes: #4045
(cherry picked from commit 03255a5a0f)
2017-08-22 14:44:39 -04:00
Mike Bayer 08f42a915a Add safe_reraise() + warnings only to Connection._autorollback
Added an exception handler that will warn for the "cause" exception on
Py2K when the "autorollback" feature of :class:`.Connection` itself
raises an exception. In Py3K, the two exceptions are naturally reported
by the interpreter as one occurring during the handling of the other.
This is continuing with the series of changes for rollback failure
handling that were last visited as part of 🎫`2696` in 1.0.12.

Change-Id: I600ba455a14ebaea27c6189889181f97c632f179
Fixes: #3946
(cherry picked from commit c0a224aba3)
2017-03-27 11:15:41 -04:00
Mike Bayer 02ae6ab3fd - add a test suite that ensures textual autocommit works
for correct expressions

Change-Id: I17d35169be914924828487abba05658dff380f2a
2017-02-13 14:17:11 -05:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 388d8db68d Accept FetchedValue, text() for column "default" value
Fixed bug whereby the :meth:`.DDLEvents.column_reflect` event would not
allow a non-textual expression to be passed as the value of the
"default" for the new column, such as a :class:`.FetchedValue`
object to indicate a generic triggered default or a
:func:`.sql.expression.text` construct.  Clarified the documentation
in this regard as well.

Fixes: #3905

Change-Id: I829796c3e9f87f375149bebee7eef133a6876d4d
2017-02-01 17:00:42 -05:00
Valery Yundin bccc1419a6 Better hide engine password
Avoid putting engine password in the exception message in
`MetaData.reflect` (since exception messages often appear in logs).
Use the same redacted `__repr__` implementation in
`TLEngine` as in its base class `Engine`

Change-Id: Ic0a7baea917a9c8d87dffdd82ef566673ab08e02
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/327
2017-01-16 14:02:26 -05:00
Mike Bayer fa6dd376bb Support python3.6
Corrects some warnings and adds tox config.  Adds DeprecationWarning
to the error category.   Large sweep for string literals w/ backslashes
as this is common in docstrings

Co-authored-by: Andrii Soldatenko
Fixes: #3886
Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
2017-01-13 10:57:41 -05:00
Mike Bayer 55ad10370f Add _extend_on deduplicating set for metadata.reflect()
The "extend_existing" option of :class:`.Table` reflection would
cause indexes and constraints to be doubled up in the case that the parameter
were used with :meth:`.MetaData.reflect` (as the automap extension does)
due to tables being reflected both within the foreign key path as well
as directly.  A new de-duplicating set is passed through within the
:meth:`.MetaData.reflect` sequence to prevent double reflection in this
way.

Change-Id: Ibf6650c1e76a44ccbe15765fd79df2fa53d6bac7
Fixes: #3861
2016-11-23 10:31:56 -05:00
Ville Skyttä e47063bfe0 Spelling fixes 2016-10-08 20:42:50 +03:00
Mike Bayer 7827dfb672 Handle BaseException in all _handle_dbapi_error
Tests illustrate that exceptions like GreenletExit and
even KeyboardInterrupt can corrupt the state of a DBAPI
connection like that of pymysql and mysqlclient.   Intercept
BaseException errors within the handle_error scheme and
invalidate just the connection alone in this case, but not
the whole pool.

The change is backwards-incompatible with a program that
currently intercepts ctrl-C within a database transaction
and wants to continue working on that transaction.  Ensure
the event hook can be used to reverse this behavior.

Change-Id: Ifaa013c13826d123eef34e32b7e79fff74f1b21b
Fixes: #3803
2016-09-21 18:39:31 -04:00
Mike Bayer 01a0a2d542 Additions to support HAAlchemy plugin
- add a connect=True key to connection record to support
  pre-loading of _ConnectionRecord objects
- ensure _ConnectionRecord.close() leaves the record in a good
  state for reopening
- add _ConnectionRecord.record_info for persistent storage
- add "in_use" accessor based on fairy_ref being present or not
- allow for the exclusions system and SuiteRequirements to be
  usable without the full plugin_base setup.
- move some Python-env requirements to the importable
  requirements.py module.
- allow starttime to be queried
- add additional events for engine plugins
- have "dialect" be a first-class parameter to the pool,
  ensure the engine strategy supplies it up front

Change-Id: Ibf549f7a1766e49d335cd6f5e26bacfaef9a8229
2016-09-16 16:20:18 -04:00
Mike Bayer 65d8deac95 - latest mysql 5.7 also crashing on XA recovery, disable
XA recovery for all MySQL

Change-Id: I4f77de521cd80c09fdf97e5bbe5dfd1c830dc3cb
2016-09-16 12:57:59 -04:00
Mike Bayer c7b9c84312 Check for supports_execution at ClauseElement base
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
2016-08-31 17:04:35 -04:00
Mike Bayer 02190234a2 - a variety of test adjustments to accomodate for MySQL 5.7
Change-Id: Ied4245433d0d7b469dae6e7394c4931d8405f387
2016-07-24 16:36:27 -04:00
Mike Bayer 7c74d702a9 Make boolean processors consistent between Py/C; coerce to 1/0
The processing performed by the :class:`.Boolean` datatype for backends
that only feature integer types has been made consistent between the
pure Python and C-extension versions, in that the C-extension version
will accept any integer value from the database as a boolean, not just
zero and one; additionally, non-boolean integer values being sent to
the database are coerced to exactly zero or one, instead of being
passed as the original integer value.

Change-Id: I01e647547fd7047bd549dd70e1fa202c51e8328b
Fixes: #3730
2016-06-23 19:58:43 -04:00
Mike Bayer e5bdf96bc0 - dont use id() to test identity as these can be recycled
Change-Id: Ie4cb4924909d55c5962f66e36cd5325e8e8f0538
2016-06-15 18:15:46 -04:00
Mike Bayer 345cc1e304 - flake8
Change-Id: I74e369d1d71c98cb0af58dde80b7d535d17cbdf7
2016-06-15 18:10:46 -04:00
Mike Bayer f38f890849 Deprecate FromClause.count()
count() here is misleading in that it not only
counts from an arbitrary column in the table, it also
does not make accommodations for DISTINCT, JOIN, etc.
as the ORM-level function does.  Core should not be
attempting to provide a function like this.

Change-Id: I9916fc51ef744389a92c54660ab08e9695b8afc2
Fixes: #3724
2016-06-14 11:48:04 -04:00
Mike Bayer 74ca7f627e - use a mock here, do away with timing problems for good. need to do this
for the rest of the timing tests

Change-Id: I06a815b1500222126a4dbc2a9a5da3ef7847e321
2016-06-02 18:40:46 -04:00
Alex Grönholm a8e7bb8782 Implemented CHECK constraint reflection for SQLite and PostgreSQL
Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Ie6cf2d2958d1c567324db9e08fef2d3186e97350
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/80
2016-06-01 12:57:36 -04:00
Mike Bayer 4856493efc Merge remote-tracking branch 'origin/pr/270' 2016-05-24 16:29:49 -04:00
Mike Bayer c124fa36d5 Support "blank" schema when MetaData.schema is set
Previously, it was impossible to have a Table that has
None for a schema name when the "schema" parameter on
MetaData was set.  A new symbol sqlalchemy.schema.BLANK_SCHEMA
is added which indicates that the schema name should unconditionally
be set to None.  In particular, this value must be passed within
cross-schema foreign key reflection, so that a Table which
is in the "default" schema can be represented properly.

Fixes: #3716
Change-Id: I3d24f99c22cded206c5379fd32a225e74edb7a8e
2016-05-18 11:43:38 -04:00
Ville Skyttä 61f9e37612 Spelling fixes: "an SQL" -> "a SQL", see #266 2016-05-05 09:02:38 +03:00
Christoph Zwerschke b59cbb5fd7 - Add support for PostgreSQL with PyGreSQL
Change-Id: I040b75ff3b4110e7e8b26442a4eb226ba8c26715
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/234
2016-04-15 12:00:27 -04:00
Mike Bayer 03d35a833c - move all resultproxy tests intio test_resultset 2016-03-30 17:36:03 -04:00
Mike Bayer dd20f56bc9 - make sure negative row indexes are based on the size of the
number of columns we're actually reporting on
- add more tests for negative row index
- changelog/migration
2016-03-30 17:27:53 -04:00
Mike Bayer 4df1e07bb9 Merge remote-tracking branch 'origin/pr/231' into pr231 2016-03-30 17:05:30 -04:00
Mike Bayer 8a776122a3 - Added connection pool events :meth:ConnectionEvents.close,
:meth:`.ConnectionEvents.detach`,
:meth:`.ConnectionEvents.close_detached`.
2016-03-25 18:31:17 -04:00
Mike Bayer 4d147c3b16 - Added basic isolation level support to the SQL Server dialects
via :paramref:`.create_engine.isolation_level` and
:paramref:`.Connection.execution_options.isolation_level`
parameters.  fixes #3534
2016-03-15 17:47:34 -04:00
Mike Bayer 2965da0a5d - handle parameter sets that aren't correctly formed, so that
for example an exception object made within a test suite can
still repr (error seen in Keystone)
2016-02-17 16:53:01 -05:00
Mike Bayer bf1d03a9e5 - do the trailing comma logic of tuple repr() exactly 2016-02-17 15:21:00 -05:00
Mike Bayer 591e0cf08a - All string formatting of bound parameter sets and result rows for
logging, exception, and  ``repr()`` purposes now truncate very large
scalar values within each collection, including an
"N characters truncated"
notation, similar to how the display for large multiple-parameter sets
are themselves truncated.
fixes #2837
2016-02-17 13:31:29 -05:00
Mike Bayer 8a1e619fb2 - revert the change first made in a6fe4dc, as we are now generalizing
the warning here to all safe_reraise() cases in Python 2.
- Revisiting 🎫`2696`, first released in 1.0.10, which attempts to
work around Python 2's lack of exception context reporting by emitting
a warning for an exception that was interrupted by a second exception
when attempting to roll back the already-failed transaction; this
issue continues to occur for MySQL backends in conjunction with a
savepoint that gets unexpectedly lost, which then causes a
"no such savepoint" error when the rollback is attempted, obscuring
what the original condition was.

The approach has been generalized to the Core "safe
reraise" function which takes place across the ORM and Core in any
place that a transaction is being rolled back in response to an error
which occurred trying to commit, including the context managers
provided by :class:`.Session` and :class:`.Connection`, and taking
place for operations such as a failure on "RELEASE SAVEPOINT".
Previously, the fix was only in place for a specific path within
the ORM flush/commit process; it now takes place for all transational
context managers as well.
fixes #2696
2016-01-28 15:01:31 -05:00
Lele Gaifax f84ef1f83c - properly handle negative indexes in RowProxy.__getitem__() 2016-01-28 09:04:40 +01:00
Mike Bayer 89facbed88 - Multi-tenancy schema translation for :class:.Table objects is added.
This supports the use case of an application that uses the same set of
:class:`.Table` objects in many schemas, such as schema-per-user.
A new execution option
:paramref:`.Connection.execution_options.schema_translate_map` is
added. fixes #2685
- latest tox doesn't like the {posargs} in the profile rerunner
2016-01-08 22:12:25 -05:00
Mike Bayer cd8adfe418 - add a do-nothing for mock url _instantiate_plugins 2016-01-06 20:10:28 -05:00
Mike Bayer c8b7729338 - Added a new entrypoint system to the engine to allow "plugins" to
be stated in the query string for a URL.   Custom plugins can
be written which will be given the chance up front to alter and/or
consume the engine's URL and keyword arguments, and then at engine
create time will be given the engine itself to allow additional
modifications or event registration.  Plugins are written as a
subclass of :class:`.CreateEnginePlugin`; see that class for
details.
fixes #3536
2016-01-06 17:20:57 -05:00
Mike Bayer 414af7b612 - The system by which a :class:.Column considers itself to be an
"auto increment" column has been changed, such that autoincrement
is no longer implicitly enabled for a :class:`.Table` that has a
composite primary key.  In order to accommodate being able to enable
autoincrement for a composite PK member column while at the same time
maintaining SQLAlchemy's long standing behavior of enabling
implicit autoincrement for a single integer primary key, a third
state has been added to the :paramref:`.Column.autoincrement` parameter
``"auto"``, which is now the default. fixes #3216
- The MySQL dialect no longer generates an extra "KEY" directive when
generating CREATE TABLE DDL for a table using InnoDB with a
composite primary key with AUTO_INCREMENT on a column that isn't the
first column;  to overcome InnoDB's limitation here, the PRIMARY KEY
constraint is now generated with the AUTO_INCREMENT column placed
first in the list of columns.
2015-10-07 10:02:45 -04:00
Mike Bayer 4096ad0f09 - Fixed critical issue whereby the pool "checkout" event handler
may be called against a stale connection without the "connect"
event handler having been called, in the case where the pool
attempted to reconnect after being invalidated and failed; the stale
connection would remain present and would be used on a subsequent
attempt.  This issue has a greater impact in the 1.0 series subsequent
to 1.0.2, as it also delivers a blanked-out ``.info`` dictionary to
the event handler; prior to 1.0.2 the ``.info`` dictionary is still
the previous one.
fixes #3497
2015-07-22 18:03:36 -04:00
Mike Bayer de906a2125 - remove the redundant non-max-row-buffer test from the max_row_buffer
test as we implemented that as a separate test.
2015-06-14 16:48:26 -04:00
Mike Bayer 9ccdea3a0f - add test cases for pullreq github:182, where we add a new
"max_row_buffer" execution option for BufferedRowResultProxy
- also add documentation, changelog and version notes
- rework the max_row_buffer argument to be interpreted from
the execution options upfront when the BufferedRowResultProxy
is first initialized.
2015-06-14 16:43:16 -04:00
Mike Bayer 54b15aaf37 - Added new engine event :meth:.ConnectionEvents.engine_disposed.
Called after the :meth:`.Engine.dispose` method is called.
2015-06-06 17:50:32 -04:00
Mike Bayer a50dcb31b9 - Fixed bug where known boolean values used by
:func:`.engine_from_config` were not being parsed correctly;
these included ``pool_threadlocal`` and the psycopg2 argument
``use_native_unicode``. fixes #3435
- add legacy_schema_aliasing config parsing for mssql
- move use_native_unicode config arg to the psycopg2 dialect
2015-05-26 10:56:23 -04:00
Mike Bayer e9921ad356 - fix some tests related to the URL change and try to make
the URL design a little simpler
2015-05-23 09:07:36 -04:00
Mike Bayer 4a0e51e7d2 - Fixed bug where in the case that a pool checkout event handler is used
and the database can no longer be connected towards, that the checkout
handler failure is caught, the attempt to re-acquire the connection
also raises an exception, but the underlying connection record
is not immediately re-checked in before the exception is propagated
outwards, having the effect that the checked-out record does not close
itself until the stack trace it's associated with is garbage collected,
preventing that record from being used for a new checkout until we
leave the scope of the stack trace.   This can lead to confusion
in the specific case of when the number of current stack traces
in memory exceeds the number of connections the pool can return,
as the pool will instead begin to raise errors about no more checkouts
available, rather than attempting a connection again.   The fix
applies a checkin of the record before re-raising.
fixes #3419
2015-05-14 13:59:04 -04:00
Mike Bayer 4992aafecc - revise the last commit with a more traditional approach
using descriptors; ensure that mock.patch() honors descriptor setters
2015-04-30 20:20:02 -04:00
Mike Bayer e0f9b279f4 - work the wrapping of the "creator" to be as resilient to
old / new style, direct access, and ad-hoc patching and
unpatching as possible
2015-04-30 19:55:28 -04:00