diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2016-09-19 18:15:02 -0400 |
---|---|---|
committer | Gerrit Code Review <gerrit2@ln3.zzzcomputing.com> | 2016-09-19 18:15:02 -0400 |
commit | e49292894a7b5a372d0e930691d65002ae1537c6 (patch) | |
tree | 64c67f5e5f2713dbe999bb9a3b08346ba5115e06 | |
parent | dc7aef1d70519e8373da12d7760267854cd1fcc4 (diff) | |
parent | 7ea54611516147a1af917691c60e1823b77c7ecf (diff) | |
download | sqlalchemy-e49292894a7b5a372d0e930691d65002ae1537c6.tar.gz |
Merge "Fix ArgumentError access in Session._add_bind"
-rw-r--r-- | doc/build/changelog/changelog_10.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 10 | ||||
-rw-r--r-- | test/orm/test_bind.py | 18 |
3 files changed, 32 insertions, 6 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 3b180f5f6..8808f6511 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -19,6 +19,16 @@ :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 :versions: 1.1.0 diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index a7440bf40..d4f1c59d8 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 c5ddf151b..cbbf24ac3 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 |