diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-06 17:13:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-06 17:16:58 -0400 |
| commit | 4e1f5377d1c5443016cc6c5ae86b8053ead41647 (patch) | |
| tree | 423ed81611f61b9f2786a2d6f4a451aebe7bb003 /lib/sqlalchemy/ext/declarative | |
| parent | 6b68a70b5f903079f3c42a827daa3ea08a1a4b53 (diff) | |
| download | sqlalchemy-4e1f5377d1c5443016cc6c5ae86b8053ead41647.tar.gz | |
Warn when declared_attr.cascading detected on mapped class
A warning is emitted if the :attr:`.declared_attr.cascading` modifier
is used with a declarative attribute that is itself declared on
a class that is to be mapped, as opposed to a declarative mixin
class or ``__abstract__`` class. The :attr:`.declared_attr.cascading`
modifier currently only applies to mixin/abstract classes.
Also add a test for @declared_attr.cascading when used on an attribute
on __abstract__.
Change-Id: Ib1b9dbe373e8be1cf24eadfed224a8988b3cd95d
Fixes: #3847
Diffstat (limited to 'lib/sqlalchemy/ext/declarative')
| -rw-r--r-- | lib/sqlalchemy/ext/declarative/api.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/ext/declarative/base.py | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py index 7c503d471..ee13a90f3 100644 --- a/lib/sqlalchemy/ext/declarative/api.py +++ b/lib/sqlalchemy/ext/declarative/api.py @@ -199,6 +199,12 @@ class declared_attr(interfaces._MappedAttribute, property): or MapperProperty-based declared attribute should be configured distinctly per mapped subclass, within a mapped-inheritance scenario. + .. note:: + + The :attr:`.declared_attr.cascading` modifier **only** applies + to the use of :class:`.declared_attr` on declarative mixin classes + and ``__abstract__`` classes. + Below, both MyClass as well as MySubClass will have a distinct ``id`` Column object established:: diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index d9433e692..3a2ac66ae 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -283,6 +283,13 @@ class _MapperConfig(object): value = dict_[k] if isinstance(value, declarative_props): + if isinstance(value, declared_attr) and value._cascading: + util.warn( + "Use of @declared_attr.cascading only applies to " + "Declarative 'mixin' and 'abstract' classes. " + "Currently, this flag is ignored on mapped class " + "%s" % self.cls) + value = getattr(cls, k) elif isinstance(value, QueryableAttribute) and \ |
