]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add the "triggering mapper" to the configure_mappers error message.
authorJohn Perkins <john.d.perkins@gmail.com>
Fri, 5 Aug 2016 17:45:49 +0000 (13:45 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 20 Sep 2016 16:11:11 +0000 (12:11 -0400)
There are cases where the originating mapper name is not
present in the exception message, such as relationship initialization
against an unmapped class.   Ensure the originating mapper is named
in the string output.

Pull-request: https://github.com/zzzeek/sqlalchemy/pull/298
Change-Id: I9f23bfa90b26dde9229ab7ec812eec9ceae48153

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/orm/mapper.py
test/ext/declarative/test_basic.py
test/orm/test_mapper.py

index a0970348911e60d784006429616a64802bfcb2f5..66f1b0cf6c1e7290265bade82cc22a5d58464265 100644 (file)
         as the order of the validators at the level of function decorator
         can't be made deterministic.
 
+    .. change::
+        :tags: bug, orm
+
+        Mapper errors raised during :func:`.configure_mappers` now explicitly
+        include the name of the originating mapper in the exception message
+        to help in those situations where the wrapped exception does not
+        itself include the source mapper.  Pull request courtesy
+        John Perkins.
 
     .. change::
         :tags: bug, mysql
index e8aa0854178a1a38b2c826fd86783c0850d9bce2..b8dc5b8c376df99adc03e6cee82f79b369237906 100644 (file)
@@ -2833,8 +2833,9 @@ def configure_mappers():
                     e = sa_exc.InvalidRequestError(
                         "One or more mappers failed to initialize - "
                         "can't proceed with initialization of other "
-                        "mappers.  Original exception was: %s"
-                        % mapper._configure_failed)
+                        "mappers. Triggering mapper: '%s'. "
+                        "Original exception was: %s"
+                        % (mapper, mapper._configure_failed))
                     e._configure_failed = mapper._configure_failed
                     raise e
                 if not mapper.configured:
index 67018d737980a39149e759596c8597aab0e3e40c..08bc04048906b12c9b5058ba311f8a294ec8a137 100644 (file)
@@ -772,9 +772,10 @@ class DeclarativeTest(DeclarativeTestBase):
         for i in range(3):
             assert_raises_message(
                 sa.exc.InvalidRequestError,
-                "^One or more mappers failed to initialize - "
-                "can't proceed with initialization of other "
-                "mappers.  Original exception was: When initializing.*",
+                "^One or more mappers failed to initialize"
+                " - can't proceed with initialization of other mappers. "
+                r"Triggering mapper: 'Mapper\|User\|users'. "
+                "Original exception was: When initializing.*",
                 configure_mappers)
 
     def test_custom_base(self):
index bc5f24fb2cfe4ce3ae92b3b467472f2cc5e8a677..045016bb3542fd1cddd74da19f5bf1a4966ef0b3 100644 (file)
@@ -153,10 +153,12 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
 
         for i in range(3):
             assert_raises_message(sa.exc.InvalidRequestError,
-                                  "^One or more mappers failed to "
-                                  "initialize - can't proceed with "
-                                  "initialization of other mappers.  "
-                                  "Original exception was: Class "
+                                  "^One or more "
+                                  "mappers failed to initialize - can't "
+                                  "proceed with initialization of other "
+                                  r"mappers. Triggering mapper\: "
+                                  r"'Mapper\|Address\|addresses'."
+                                  " Original exception was: Class "
                                   "'test.orm._fixtures.User' is not mapped$",
                                   configure_mappers)