summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/interfaces.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-09 02:01:16 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-01-25 20:59:08 -0500
commit2eb3f211dae1188a6c1b3664f612f4628fd7b9a9 (patch)
tree71d3df245ef979145ac3eabfeae1afe9cee68c05 /lib/sqlalchemy/orm/interfaces.py
parentf0b344ee9db22085ede906f1041cd6680e2682e3 (diff)
downloadsqlalchemy-2eb3f211dae1188a6c1b3664f612f4628fd7b9a9.tar.gz
Improve error messages in the area of loader options
Improved error messages emitted by the ORM in the area of loader option traversal. This includes early detection of mis-matched loader strategies along with a clearer explanation why these strategies don't match. Fixes: #4433 Change-Id: I3351b64241f7f62ca141a0be95085e6ef8ca6d32
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 87b4cfcde..d2b08a908 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -22,6 +22,7 @@ from __future__ import absolute_import
import collections
+from . import exc as orm_exc
from . import path_registry
from .base import _MappedAttribute # noqa
from .base import EXT_CONTINUE
@@ -536,7 +537,7 @@ class StrategizedProperty(MapperProperty):
try:
return self._strategies[key]
except KeyError:
- cls = self._strategy_lookup(*key)
+ cls = self._strategy_lookup(self, *key)
self._strategies[key] = self._strategies[cls] = strategy = cls(
self, key
)
@@ -592,7 +593,7 @@ class StrategizedProperty(MapperProperty):
return decorate
@classmethod
- def _strategy_lookup(cls, *key):
+ def _strategy_lookup(cls, requesting_property, *key):
for prop_cls in cls.__mro__:
if prop_cls in cls._all_strategies:
strategies = cls._all_strategies[prop_cls]
@@ -600,7 +601,23 @@ class StrategizedProperty(MapperProperty):
return strategies[key]
except KeyError:
pass
- raise Exception("can't locate strategy for %s %s" % (cls, key))
+
+ for property_type, strats in cls._all_strategies.items():
+ if key in strats:
+ intended_property_type = property_type
+ actual_strategy = strats[key]
+ break
+ else:
+ intended_property_type = None
+ actual_strategy = None
+
+ raise orm_exc.LoaderStrategyException(
+ cls,
+ requesting_property,
+ intended_property_type,
+ actual_strategy,
+ key,
+ )
class MapperOption(object):