diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-29 23:53:10 -0600 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-30 21:06:27 -0600 |
| commit | 147f6d382c3b6f06c8efa5a24c07c9849473e7af (patch) | |
| tree | b3c1288d8d493bba638a3b07fd2bfdc7defa8fa6 /lib/sqlalchemy/ext/declarative/base.py | |
| parent | b8f9517cddf41dbb47ae4ad120141c7ab1a29ac5 (diff) | |
| download | sqlalchemy-147f6d382c3b6f06c8efa5a24c07c9849473e7af.tar.gz | |
Add informative failure modes to _DeferredMapperConfig
Added some helper exceptions that invoke when a mapping based on
:class:`.AbstractConcreteBase`, :class:`.DeferredReflection`, or
:class:`.AutoMap` is used before the mapping is ready to be used, which
contain descriptive information on the class, rather than falling through
into other failure modes that are less informative.
Fixes: #4470
Change-Id: I9bc51697f63cedaa7809a0adb17b2398c209e289
Diffstat (limited to 'lib/sqlalchemy/ext/declarative/base.py')
| -rw-r--r-- | lib/sqlalchemy/ext/declarative/base.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index 80cd23bc8..62db282d1 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -15,6 +15,7 @@ from ... import event from ... import exc from ... import util from ...orm import class_mapper +from ...orm import exc as orm_exc from ...orm import mapper from ...orm import synonym from ...orm.attributes import QueryableAttribute @@ -717,6 +718,17 @@ class _DeferredMapperConfig(_MapperConfig): return isinstance(class_, type) and weakref.ref(class_) in cls._configs @classmethod + def raise_unmapped_for_cls(cls, class_): + if hasattr(class_, "_sa_raise_deferred_config"): + class_._sa_raise_deferred_config() + + raise orm_exc.UnmappedClassError( + class_, + msg="Class %s has a deferred mapping on it. It is not yet " + "usable as a mapped class." % orm_exc._safe_cls_name(class_), + ) + + @classmethod def config_for_cls(cls, class_): return cls._configs[weakref.ref(class_)] |
