From e95aa257aa3145a5db478d33fb1803494a38b46d Mon Sep 17 00:00:00 2001 From: John Perkins Date: Fri, 5 Aug 2016 13:45:49 -0400 Subject: [PATCH] Add the "triggering mapper" to the configure_mappers error message. 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 | 8 ++++++++ lib/sqlalchemy/orm/mapper.py | 5 +++-- test/ext/declarative/test_basic.py | 7 ++++--- test/orm/test_mapper.py | 10 ++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index a097034891..66f1b0cf6c 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -64,6 +64,14 @@ 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 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index e8aa085417..b8dc5b8c37 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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: diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 67018d7379..08bc040489 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -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): diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index bc5f24fb2c..045016bb35 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -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) -- 2.47.2