diff options
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 6 | ||||
-rw-r--r-- | test/ext/test_declarative.py | 21 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index b58685414..efaf8f8db 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -1030,6 +1030,12 @@ def _as_declarative(cls, classname, dict_): if base is not cls: inherited_table_args = True elif class_mapped: + if isinstance(obj, declarative_props): + util.warn("Regular (i.e. not __special__) " + "attribute '%s.%s' uses @declared_attr, " + "but owning class %s is mapped - " + "not applying to subclass %s." + % (base.__name__, name, base, cls)) continue elif base is not cls: # we're a mixin. diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index e338ef039..d8be6ac8e 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -799,6 +799,27 @@ class DeclarativeTest(DeclarativeTestBase): eq_(sess.query(User).all(), [User(name='u1', address_count=2, addresses=[Address(email='one'), Address(email='two')])]) + def test_useless_declared_attr_warns_on_subclass(self): + def go(): + class MyBase(Base): + __tablename__ = 'foo' + id = Column(Integer, primary_key=True) + @declared_attr + def somecol(cls): + return Column(Integer) + + class MyClass(MyBase): + __tablename__ = 'bar' + assert_raises_message( + sa.exc.SAWarning, + r"Regular \(i.e. not __special__\) attribute 'MyBase.somecol' " + "uses @declared_attr, but owning class " + "<class 'test.ext.test_declarative.MyBase'> is " + "mapped - not applying to subclass <class " + "'test.ext.test_declarative.MyClass'>.", + go + ) + def test_column(self): class User(Base, fixtures.ComparableEntity): |