summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-09-14 15:11:13 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-09-19 15:58:19 -0400
commit7ea54611516147a1af917691c60e1823b77c7ecf (patch)
tree4f7ee4952d7a244b8a6bf9024ba3fdcfd5f3aa25
parent881369b949cff44e0017fdc28d9722ef3c26171a (diff)
downloadsqlalchemy-7ea54611516147a1af917691c60e1823b77c7ecf.tar.gz
Fix ArgumentError access in Session._add_bind
Fixes: #3798 Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293
-rw-r--r--doc/build/changelog/changelog_10.rst10
-rw-r--r--lib/sqlalchemy/orm/session.py10
-rw-r--r--test/orm/test_bind.py18
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