Commit Graph

51 Commits

Author SHA1 Message Date
Mike Bayer 03255a5a0f 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
2017-08-18 13:04:14 -04:00
Mike Bayer c0a224aba3 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
2017-03-27 11:14:24 -04:00
Mike Bayer f881dae817 Integrate "pre-ping" into connection pool.
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
2017-03-20 18:01:23 -04:00
Mike Bayer 7b07ea67dc - add ad_hoc_engines to remove RealReconnectTest from oracle
Change-Id: Ie40aeba87dcfe9e8216abb8be050e7c2cc5b5ec9
2017-03-14 09:14:37 -04: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 cd8adfe418 - add a do-nothing for mock url _instantiate_plugins 2016-01-06 20:10:28 -05: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 068f9a1531 - Fixed bug in :class:.Connection and pool where the
:meth:`.Connection.invalidate` method, or an invalidation due
to a database disconnect, would fail if the
``isolation_level`` parameter had been used with
:meth:`.Connection.execution_options`; the "finalizer" that resets
the isolation level would be called on the no longer opened connection.
fixes #3302
2015-02-04 18:51:24 -05:00
Mike Bayer b7cf11b163 - simplify the "noconnection" error handling, setting
_handle_dbapi_exception_noconnection() to only invoke in the case
of raw_connection() in the constructor of Connection.   in all other
cases the Connection proceeds with _handle_dbapi_exception() including
revalidate.
2014-12-08 14:05:20 -05:00
Mike Bayer b8114a3576 - adjust _revalidate_connection() again such that we pass a _wrap=False
to it, so that we say we will do the wrapping just once right here
in _execute_context() / _execute_default().  An adjustment is made
to _handle_dbapi_error() to not assume self.__connection in case
we are already in an invalidated state

further adjustment to
0639c199a5, 41e7253dee, #3266
2014-12-05 19:08:47 -05:00
Mike Bayer b89523f0b7 - Fixed bug where a "branched" connection, that is the kind you get
when you call :meth:`.Connection.connect`, would not share transaction
status with the parent.  The architecture of branching has been tweaked
a bit so that the branched connection defers to the parent for
all transactional status and operations.
fixes #3190
2014-09-26 16:25:26 -04:00
Mike Bayer fbddf193a6 - Fixed bug where a "branched" connection, that is the kind you get
when you call :meth:`.Connection.connect`, would not share invalidation
status with the parent.  The architecture of branching has been tweaked
a bit so that the branched connection defers to the parent for
all invalidation status and operations.
fixes #3215
2014-09-26 14:55:36 -04:00
Tony Locke f586754c86 PEP8 tidy of test/engine/test_reconnect 2014-08-02 15:29:36 +01:00
Mike Bayer fe878f5aff - more pg8000 tests passing 2014-07-25 16:39:44 -04:00
Mike Bayer 814637e291 - vastly improve the "safe close cursor" tests in test_reconnect
- Fixed bug which would occur if a DBAPI exception
occurs when the engine first connects and does its initial checks,
and the exception is not a disconnect exception, yet the cursor
raises an error when we try to close it.  In this case the real
exception would be quashed as we tried to log the cursor close
exception via the connection pool and failed, as we were trying
to access the pool's logger in a way that is inappropriate
in this very specific scenario. fixes #3063
2014-05-30 16:24:38 -04:00
Alex Gaynor 1caa7fafbd Fix many typos throughout the codebase
Found using: https://github.com/intgr/topy
2014-04-26 13:13:13 -07:00
Mike Bayer 82a67abf4b - fix the uuid routine here to not run out of uuids 2014-03-24 11:57:38 -04:00
Mike Bayer eed9cfc3ae - A major improvement made to the mechanics by which the :class:.Engine
recycles the connection pool when a "disconnect" condition is detected;
instead of discarding the pool and explicitly closing out connections,
the pool is retained and a "generational" timestamp is updated to
reflect the current time, thereby causing all existing connections
to be recycled when they are next checked out.   This greatly simplifies
the recycle process, removes the need for "waking up" connect attempts
waiting on the old pool and eliminates the race condition that many
immediately-discarded "pool" objects could be created during the
recycle operation. fixes #2985
2014-03-22 18:45:39 -04:00
Mike Bayer 59ca4633ac - remove informix dialect, moved out to https://bitbucket.org/zzzeek/sqlalchemy_informixdb
- remove informix, maxdb, access symbols from tests etc.
2013-11-17 13:45:23 -05:00
Mike Bayer fd55be01dd Dialect.initialize() is not called a second time if an :class:.Engine
is recreated, due to a disconnect error.   This fixes a particular
issue in the Oracle 8 dialect, but in general the dialect.initialize()
phase should only be once per dialect.  Also in 0.8.3. [ticket:2776]
2013-07-11 15:15:09 -04:00
Mike Bayer b38a76cd1d - replace most explicitly-named test objects called "Mock..." with
actual mock objects from the mock library.  I'd like to use mock
for new tests so we might as well use it in obvious places.
- use unittest.mock in py3.3
- changelog
- add a note to README.unittests
- add tests_require in setup.py
- have tests import from sqlalchemy.testing.mock
- apply usage of mock to one of the event tests.  we can be using
this approach all over the place.
2013-06-30 18:35:12 -04:00
Mike Bayer f9bb6c2a54 - additional oracle fixes. cx_oracle under py3k is complaining about tuples to executemany(),
so just unconditionally turn this into a list
- this one test segfaults only on py3k + cx_oracle
2013-05-27 17:06:05 -04:00
Mike Bayer be523db4a2 merge default 2013-04-30 10:03:14 -04:00
Mike Bayer 62eeb1bf26 missing comma 2013-04-30 00:15:36 -04:00
Mike Bayer e082ca503c merge default 2013-04-29 19:50:49 -04:00
Mike Bayer eb431e4aa5 Updated mysqlconnector dialect to check for disconnect based
on the apparent string message sent in the exception; tested
against mysqlconnector 1.0.9.
2013-04-29 19:49:28 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer 1b9c1a2ecf - test + changelog for [ticket:2691] 2013-04-18 12:01:16 -04:00
Mike Bayer ee7bb9c174 Improvements to Connection auto-invalidation
handling.  If a non-disconnect error occurs,
but leads to a delayed disconnect error within error
handling (happens with MySQL), the disconnect condition
is detected.  The Connection can now also be closed
when in an invalid state, meaning it will raise "closed"
on next usage, and additionally the "close with result"
feature will work even if the autorollback in an error
handling routine fails and regardless of whether the
condition is a disconnect or not.
[ticket:2695]
2013-04-11 19:10:02 -04:00
Hajime Nakagami 220f2b851a mymysql dialect 2013-03-01 00:00:18 +09:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer e597d3d145 - [bug] Fixed bug whereby if a database restart
affected multiple connections, each
connection would individually invoke a new
disposal of the pool, even though only
one disposal is needed.  [ticket:2522]
2012-06-22 12:42:01 -04:00
Mike Bayer 632043bc8a - [bug] Fixed bug whereby transaction.rollback()
would throw an error on an invalidated
connection if the transaction were a
two-phase or savepoint transaction.
For plain transactions, rollback() is a no-op
if the connection is invalidated, so while
it wasn't 100% clear if it should be a no-op,
at least now the interface is consistent.
[ticket:2317]
2011-12-04 14:25:00 -05:00
Mike Bayer ca3ef312d2 - make sure we definitely get every connection created
- ensure we lose self.conns, cx_oracle only closes on __del__
- fix reconnectingfixture to lose all connection references
2011-05-14 13:34:29 -04:00
Mike Bayer e1ec36fc9e - hardcore force every connection into a strong-referenced set, rollback on every test, close on every context.
this uses pool events but bypasses the pool's fairy/record/dispose services.   pypy still seems to expose
some holes in that at least as far as what some (or maybe just one, cant find it yet) of the tests does.
haven't tested this too deeply, just on sqlite + postgres, cypthon 2.7 + pypy.   will see what the buildbot
says
2011-04-25 21:50:26 -04:00
Mike Bayer 68a350d462 - remove test.sql._base, test.engine._base, test.orm._base, move those classes to a new test.lib.fixtures module
- move testing.TestBase to test.lib.fixtures
- massive search and replace
2011-03-27 16:27:27 -04:00
Mike Bayer 7e8f351097 - Non-DBAPI errors which occur in the scope of an execute()
call are now wrapped in sqlalchemy.exc.StatementError,
and the text of the SQL statement and repr() of params
is included.  This makes it easier to identify statement
executions which fail before the DBAPI becomes
involved.  [ticket:2015]
2011-02-09 18:11:40 -05:00
Mike Bayer 6f16b8db6f - add connection and cursor to is_disconnect(). We aren't using it yet,
but we'd like to.   Most DBAPIs don't give us anything we can do with it.
Some research was done on psycopg2 and it still seems like they give us
no adequate method (tried connection.closed, cursor.closed, connection.status).
mxodbc claims their .closed attribute will work (but I am skeptical).
- remove beahvior in pool that auto-invalidated a connection when
the cursor failed to create.  That's not the pool's job.  we need the conn
for the error logic.  Can't get any tests to fail, curious why that
behavior was there, guess we'll find out (or not).
- add support for psycopg2 version detection.  even though we have
no use for it yet...
- adjust one of the reconnect tests to work with oracle's
horrendously slow connect speed
2011-02-09 15:06:32 -05:00
Mike Bayer 1515073b96 - New DBAPI support for pymysql, a pure Python port
of MySQL-python.  [ticket:1991]
2011-01-26 11:18:03 -05:00
Mike Bayer 350aed3fdb - whitespace removal bonanza 2011-01-02 14:23:42 -05:00
Mike Bayer 58b2939433 - sqlalchemy.test and nose plugin moves back to being entirely
outside of "sqlalchemy" and under "test/".

Rationale:

- coverage plugin works without issue, without need for an awkward
additional package install
- command line for "nosetests" isn't polluted with SQLAlchemy options

[ticket:1949]
2010-11-28 14:19:44 -05:00
Mike Bayer 98674959d2 - initial patch for [ticket:1926] 2010-11-17 17:54:52 -05:00
Mike Bayer e1402efb19 - move sqlalchemy.test to test.lib 2010-11-15 19:37:50 -05:00
Mike Bayer 761b4f29e2 - *Major* cleanup / modernization of the Informix
dialect for 0.6, courtesy Florian Apolloner.
[ticket:1906]
2010-10-01 21:26:05 -04:00
Mike Bayer 7d3a916fc3 - replaced all self.__connection.is_valid with
"safe" self._connection_is_valid.
- Fixed bug in Connection whereby if a "disconnect"
event occurred in the "initialize" phase of the
first connection pool connect, an AttributeError
would be raised when the Connection would attempt
to invalidate the DBAPI connection.  [ticket:1894]
- Connection.invalidate() can be called more than
once and subsequent calls do nothing.
2010-08-26 01:33:51 -04:00
Mike Bayer a6b62cc3fe Python-tidy test/engine and test/aaa_profiling, 80% auto + 20% manual intervention 2010-07-11 13:15:51 -04:00
Mike Bayer 41d2e24c4a merge tip 2010-05-03 19:32:34 -04:00
Mike Bayer 74a8723df3 - Fixed bug in connection pool cursor wrapper whereby if a
cursor threw an exception on close(), the logging of the
message would fail.  [ticket:1786]
2010-04-28 16:16:56 -04:00
Mike Bayer 8fc5005dfe merge 0.6 series to trunk. 2009-08-06 21:11:27 +00:00