]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix ArgumentError access in Session._add_bind
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Sep 2016 19:11:13 +0000 (15:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 Sep 2016 20:00:18 +0000 (16:00 -0400)
Fixes: #3798
Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293
(cherry picked from commit 7ea54611516147a1af917691c60e1823b77c7ecf)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/session.py
test/orm/test_bind.py

index 0e418423345e9283e8025d3871ab6f542131d280..5f9a35f688932dba157e50bdbef239afc81fe714 100644 (file)
 .. 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
index 000441fb95ef8530374420314e15ebabbcb934d2..9a3e1269bbdf8520eef4f0c5d67c3dfcaeb88ddb 100644 (file)
@@ -1113,9 +1113,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:
@@ -1126,9 +1125,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`
index c5ddf151b55ea4dcaf8441e1d48877eaa67601f8..cbbf24ac3e38fa2b3aa5ae89ab3aa4d048b3fab6 100644 (file)
@@ -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