Add a decorator retry_on_deadlock(). All db.api functions marked
with this decorator will be retried if a DBDeadlock exception is
received.
Change-Id: I3488bfec67ec1c563292f1b61a7a9697f118809c
Closes-bug: 1348588
This method was prematurely removed from oslo.db without
a deprecation phase, when Alembic added support for
foreign key autodetection. oslo.db continues to use
alembic for this purpose, however the
ModelsMigrationsSync.check_foreign_keys() method is restored
directly for those projects which were calling into it
explicitly.
Change-Id: Id892567bd60d6b4b88765bbfe3cd5c5e75910b25
The second call to connection.scalar() inside of _connect_ping_listener()
is not subject to the exc_filters system under SQLAlchemy 0.9 and earlier,
in the case that the attempt to revalidate within fails. This causes
the exception to be propagated outwards as the original
OperationalError (assuming that's what the DBAPI raised, as is typical),
rather than it being wrapped again in DBConnectionError.
SQLAlchemy 1.0 has altered this behavior such that the handle_error()
listener is invoked correctly for revalidiation attempts (it was being
invoked before, but without the correct state), as well as
for initial connect attempts, as part of
https://bitbucket.org/zzzeek/sqlalchemy/issue/3266/. For 0.9 and earlier,
we here backport this system into oslo/db/sqlalchemy/compat.py,
including that we redefine the connection pool's handler to re-throw
the original dbapi.Error instance directly, then move the handling
of this error in terms of SQLAlchemy wrapping and events into
the Engine and Connection. The approach here works back to
SQLAlchemy 0.8, and is conditional based on whether or not
SQLAlchemy 1.0 is detected.
Change-Id: I455e957b043318a8500909c66cadde53228b52d6
When doing query.order_by, sort_key_attr is get from model class,
we need to make sure sort_key_attr is really a QueryableAttribute
type instance before we do the query or it will cause errors.
This will prevent if there IS a function which name is same as sort_key.
Closes-Bug: 1405069
Change-Id: I8a3eb08ab3469ec08e05bfce754b664943d65c83
The default setting for oslo.db is TRADITIONAL for mysql_sql_mode;
this is set up in oslo_db/options.py as well as
in EngineFacade; however, the provisioning system currently does not
use these options or EngineFacade, and the default for
mysql_sql_mode in the base session.create_engine() is None.
For a MySQL/MariaDB database where this is not established in my.cnf,
tests will run without TRADITIONAL SQL mode and some tests will fail,
including some Nova migration tests that rely upon this.
This patch resolves that as well as the warning we see
in tests regarding the empty SQL mode.
Change-Id: I3acdc0fb30327f56a76ee299cc6bade7c5a7e312
After we moved out from the namespaces, tests were moved to
oslo_db/tests. The code in oslo_db.sqlalchemy.session filters out
lines from modules under oslo_db, so the test filename does not
appear in the context for the error message.
Use patched traceback module in tests to fix it.
Closes-Bug: #1405376
Change-Id: Id6022c065dfe13351fca5e54baa343d6c96b0270
Currently PostgreSQL connection errors are not wrapped with our
custom DBConnectionError and engine.connect() will raise
OperationalError instead.
Change-Id: Iefdb9a99ca0cbe982bf12cb7e1ac47996fc5a025
Move the public API out of oslo.db to oslo_db. Retain the ability to
import from the old namespace package for backwards compatibility for
this release cycle.
Blueprint: drop-namespace-packages
Change-Id: Ie96b482b9fbcb1d85203ad35bb65c1f43e912a44