Not all db.sqal.session methods are wrapped by wrap_db_error

Bug #1214341 reported by Boris Pavlovic
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Undecided
Ivan Kolodyazhny
Ironic
Fix Released
Undecided
Viktor Serhieiev
OpenStack Identity (keystone)
Fix Released
High
Ilya Pekelny
oslo-incubator
Fix Released
High
Mike Bayer

Bug Description

first(), all(), begin(), commit() and other public methods could produce amount of exceptions, that should be wrapped in exception in any case.

Tags: db
Changed in oslo:
assignee: nobody → Boris Pavlovic (boris-42)
status: New → In Progress
importance: Undecided → High
Revision history for this message
Mark McLoughlin (markmc) wrote :

Was there a patch posted for this?

Is it still an issue?

Changed in oslo:
status: In Progress → Incomplete
Changed in oslo:
assignee: Boris Pavlovic (boris-42) → nobody
Revision history for this message
Mike Bayer (zzzeek) wrote :

part of what I'm looking into is to support oslo.db being able to intercept and accommodate DB-level exceptions at the Core level, rather than the ORM level. Wrapping ORM methods means the exceptions are being intercepted at any number of endpoints, when in fact the exceptions are generated up the tree at a much smaller number of locations. SQLAlchemy has a standard Core-level exception handling routine, so being able to take advantage of this means that exception-rewriting can in fact occur in exactly one place, and it will be hit for all DBAPI interactions that raise an exception.

Right now the exception-handling routine has a pluggable event hook in it, which allows inspection of the raw DBAPI exception. Theoretically it can be used to re-raise a new exception, though the hook should be modified slightly to support this fully. To use the hook as public API would therefore require SQLAlchemy 0.9 and probably an unreleased 0.9.X version. The same general methodology is possible with any 0.9.x, 0.8.x or 0.7.x version using a "wrapping" approach, that would require use of two underscored attributes, wrapping the _handle_dbapi_exception() method, which would make use of Engine._connection_cls in order to invoke. if SQLAlchemy releases a "blessed" API hook, oslo.db could use version detection to safely choose between blessed API vs. wrapping-on-known-SQLAlchemy-version.

Regardless of the timeframe / version requirements for this to happen, it's my recommendation that ultimately, DBAPI exception rewriting occur at the Core level using events which would eliminate the need for endpoint level exception catching. I'll be putting down my recommendations soon at some more well-defined place (like a wiki page).

Revision history for this message
Ben Nemec (bnemec) wrote :

Good stuff. :-)

I think a spec would be the best place to capture the details of this work now: https://github.com/openstack/oslo-specs/blob/master/specs/template.rst We've started using those so everyone has a reasonable way to view and comment on new feature work before it gets approved.

Changed in oslo:
assignee: nobody → Mike Bayer (zzzeek)
status: Incomplete → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.db (master)

Reviewed: https://review.openstack.org/105891
Committed: https://git.openstack.org/cgit/openstack/oslo.db/commit/?id=0a6c8a8a0eb8a2034758488bb4897c4c9d2a964a
Submitter: Jenkins
Branch: master

commit 0a6c8a8a0eb8a2034758488bb4897c4c9d2a964a
Author: Mike Bayer <email address hidden>
Date: Wed Jul 9 17:44:08 2014 -0400

    Implement new exception interception and filtering layer

    Replace @_wrap_db_error() with an event-based system
    that leverages the new SQLAlchemy handle_error() event.

    The internal logic of @_wrap_db_error() is replaced by a
    system of declarative filters, which is also expressed
    on the testing side using a new test framework for these
    conditions.

    partially implement bp: use-events-for-error-wrapping
    Closes-Bug: #1214341
    Change-Id: Ib8c7f8d5c6f44c49a53dd6411adbf8aaaecb74be

Changed in oslo:
status: In Progress → Fix Committed
Ilya Pekelny (i159)
Changed in keystone:
assignee: nobody → Ilya Pekelny (i159)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

Fix proposed to branch: master
Review: https://review.openstack.org/108935

Revision history for this message
Viktor Serhieiev (vsergeyev) wrote :

This bug also affects Keystone and Ironic, because these project checks for the sqlalchemy.exc.IntegrityError exception (instead of oslo.db.exception.DBDuplicateEntry), when they checks unit constrains in migration testing.

Changed in ironic:
assignee: nobody → Victor Sergeyev (vsergeyev)
status: New → In Progress
Changed in oslo:
milestone: none → juno-2
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ironic (master)

Reviewed: https://review.openstack.org/108943
Committed: https://git.openstack.org/cgit/openstack/ironic/commit/?id=82de9e34d0cf7343aae77c78b0b645ac1765ac35
Submitter: Jenkins
Branch: master

commit 82de9e34d0cf7343aae77c78b0b645ac1765ac35
Author: Victor Sergeyev <email address hidden>
Date: Wed Jul 23 13:15:23 2014 +0300

    Catch oslo.db error instead of sqlalchemy error

    The latest oslo.db code wraps all sqlalchemy exceptions and re-raise
    them as oslo.db exceptions. But there is a single case in Ironic when
    we suppose to get sqlalchemy exception, so this will break unittest,
    when the new version of oslo.db will come.

    Added check for the new oslo.db exception, left the old check for the
    compatibility.

    Closes-Bug: #1214341
    Change-Id: Iae5599948d29778ac416edf31d3b1b2f7a8a54a9

Changed in ironic:
status: In Progress → Fix Committed
Changed in ironic:
milestone: none → juno-2
status: Fix Committed → Fix Released
Ivan Kolodyazhny (e0ne)
Changed in cinder:
assignee: nobody → Ivan Kolodyazhny (e0ne)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/108935
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=9231482360aa7765d7b4f0e887533aceaff59e53
Submitter: Jenkins
Branch: master

commit 9231482360aa7765d7b4f0e887533aceaff59e53
Author: Ilya Pekelny <email address hidden>
Date: Wed Jul 23 12:32:48 2014 +0300

    Catch correct oslo.db exception

    Now oslo.db wraps all the database exceptions into specific oslo.db
    exceptions. A test expects for IntegrityError where now returns
    DBDuplicateEntry. We should catch DBDuplicateEntry to keep test
    correctness.

    Change-Id: I4576f19c4fd3db6742a6a2fbbca0e0e5400b792d
    Closes-Bug: #1214341

Changed in keystone:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/111760

Changed in cinder:
status: New → In Progress
Thierry Carrez (ttx)
Changed in keystone:
milestone: none → juno-3
status: Fix Committed → Fix Released
Dolph Mathews (dolph)
Changed in keystone:
importance: Undecided → High
Thierry Carrez (ttx)
Changed in keystone:
milestone: juno-3 → 2014.2
Thierry Carrez (ttx)
Changed in ironic:
milestone: juno-2 → 2014.2
Revision history for this message
Sean McGinnis (sean-mcginnis) wrote :

Automatically unassigning due to inactivity.

Changed in cinder:
assignee: Ivan Kolodyazhny (e0ne) → nobody
status: In Progress → Triaged
Ivan Kolodyazhny (e0ne)
Changed in cinder:
status: Triaged → Fix Released
assignee: nobody → Ivan Kolodyazhny (e0ne)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.