]> 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 19:58:19 +0000 (15:58 -0400)
Fixes: #3798
Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293

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

index 3b180f5f697641aa47a1abb71eea6bb4c6ee9868..8808f6511c8d064fffa3949870419c305dc53b26 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 a7440bf40874fecfbec103a84e75eeba7d87efb1..d4f1c59d8a86c033a7b2eb8d2e4395a901af83ee 100644 (file)
@@ -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`
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