From: Mike Bayer Date: Wed, 14 Sep 2016 19:11:13 +0000 (-0400) Subject: Fix ArgumentError access in Session._add_bind X-Git-Tag: rel_1_1_0~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ea54611516147a1af917691c60e1823b77c7ecf;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix ArgumentError access in Session._add_bind Fixes: #3798 Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 3b180f5f69..8808f6511c 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,16 @@ .. changelog:: :version: 1.0.16 + .. change:: + :tags: bug, orm + :tickets: 3798 + :versions: 1.1.0 + + Fixed bug where the ArgumentError raised for an invalid bind + sent to a Session via :meth:`.Session.bind_mapper`, + :meth:`.Session.bind_table`, + or the constructor would fail to be correctly raised. + .. change:: :tags: bug, mssql :tickes: 3791 diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index a7440bf408..d4f1c59d8a 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1122,9 +1122,8 @@ class Session(_SessionClassMethods): insp = inspect(key) except sa_exc.NoInspectionAvailable: if not isinstance(key, type): - raise exc.ArgumentError( - "Not acceptable bind target: %s" % - key) + raise sa_exc.ArgumentError( + "Not an acceptable bind target: %s" % key) else: self.__binds[key] = bind else: @@ -1135,9 +1134,8 @@ class Session(_SessionClassMethods): for selectable in insp._all_tables: self.__binds[selectable] = bind else: - raise exc.ArgumentError( - "Not acceptable bind target: %s" % - key) + raise sa_exc.ArgumentError( + "Not an acceptable bind target: %s" % key) def bind_mapper(self, mapper, bind): """Associate a :class:`.Mapper` with a "bind", e.g. a :class:`.Engine` diff --git a/test/orm/test_bind.py b/test/orm/test_bind.py index c5ddf151b5..cbbf24ac3e 100644 --- a/test/orm/test_bind.py +++ b/test/orm/test_bind.py @@ -138,6 +138,24 @@ class BindIntegrationTest(_fixtures.FixtureTest): sess.close() + def test_bind_arg(self): + sess = Session() + + assert_raises_message( + sa.exc.ArgumentError, + "Not an acceptable bind target: foobar", + sess.bind_mapper, "foobar", testing.db + ) + + mapper(self.classes.User, self.tables.users) + u_object = self.classes.User() + + assert_raises_message( + sa.exc.ArgumentError, + "Not an acceptable bind target: User()", + sess.bind_mapper, u_object, testing.db + ) + @engines.close_open_connections def test_bound_connection(self): users, User = self.tables.users, self.classes.User