summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Perkins <john.d.perkins@gmail.com>2016-08-05 13:45:49 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-09-20 12:11:11 -0400
commite95aa257aa3145a5db478d33fb1803494a38b46d (patch)
tree1e235379669c56444d21a3fa50b1e91d008686db
parent881369b949cff44e0017fdc28d9722ef3c26171a (diff)
downloadsqlalchemy-e95aa257aa3145a5db478d33fb1803494a38b46d.tar.gz
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
-rw-r--r--doc/build/changelog/changelog_11.rst8
-rw-r--r--lib/sqlalchemy/orm/mapper.py5
-rw-r--r--test/ext/declarative/test_basic.py7
-rw-r--r--test/orm/test_mapper.py10
4 files changed, 21 insertions, 9 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index a09703489..66f1b0cf6 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 e8aa08541..b8dc5b8c3 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 67018d737..08bc04048 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 bc5f24fb2..045016bb3 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)