summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-26 11:03:07 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-26 11:36:08 -0400
commitec1700ba29f7f15859ee6576855a4d6675265640 (patch)
tree2b2f19bbcc5906139a1b88c527d46e64eceaf4bd /test/ext
parent1b0b35f254f545dbeb3ad6e2215ba24ae1c02894 (diff)
downloadsqlalchemy-ticket_4091.tar.gz
Warnings for @declared_attr.cascadingticket_4091
A warning is emitted if a subclass attempts to override an attribute that was declared on a superclass using ``@declared_attr.cascading`` that the overridden attribute will be ignored. This use case cannot be fully supported down to further subclasses without more complex development efforts, so for consistency the "cascading" is honored all the way down regardless of overriding attributes. A warning is emitted if the ``@declared_attr.cascading`` attribute is used with a special declarative name such as ``__tablename__``, as this has no effect. Ensure that documenation refers to the current inconsistency that __tablename__ can be overridden by subclasses however @declared_attr.cascading cannot. Fixes: #4091 Fixes: #4092 Change-Id: I3aecdb2f99d408e404a1223f5ad86ae3c7fdf036
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/declarative/test_mixin.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/ext/declarative/test_mixin.py b/test/ext/declarative/test_mixin.py
index be169bcda..0b1b117fb 100644
--- a/test/ext/declarative/test_mixin.py
+++ b/test/ext/declarative/test_mixin.py
@@ -1,5 +1,5 @@
from sqlalchemy.testing import eq_, assert_raises, \
- assert_raises_message, is_
+ assert_raises_message, is_, expect_warnings
from sqlalchemy.ext import declarative as decl
import sqlalchemy as sa
from sqlalchemy import testing
@@ -1613,6 +1613,30 @@ class DeclaredAttrTest(DeclarativeTestBase, testing.AssertsCompiledSQL):
eq_(counter.mock_calls, [mock.call(A), mock.call(B)])
+ def test_property_cascade_mixin_override(self):
+ counter = mock.Mock()
+
+ class Mixin(object):
+ @declared_attr.cascading
+ def my_prop(cls):
+ counter(cls)
+ return column_property(cls.x + 2)
+
+ class A(Base, Mixin):
+ __tablename__ = 'a'
+
+ id = Column(Integer, primary_key=True)
+ x = Column(Integer)
+
+ with expect_warnings(
+ "Attribute 'my_prop' on class .*B.* "
+ "cannot be processed due to @declared_attr.cascading; "
+ "skipping"):
+ class B(A):
+ my_prop = Column('foobar', Integer)
+
+ eq_(counter.mock_calls, [mock.call(A), mock.call(B)])
+
def test_property_cascade_abstract(self):
counter = mock.Mock()
@@ -1635,6 +1659,21 @@ class DeclaredAttrTest(DeclarativeTestBase, testing.AssertsCompiledSQL):
eq_(counter.mock_calls, [mock.call(A), mock.call(B)])
+ def test_warn_cascading_used_w_tablename(self):
+ class Mixin(object):
+ @declared_attr.cascading
+ def __tablename__(cls):
+ return "foo"
+
+ with expect_warnings(
+ "@declared_attr.cascading is not supported on the "
+ "__tablename__ attribute on class .*A."
+ ):
+ class A(Mixin, Base):
+ id = Column(Integer, primary_key=True)
+
+ eq_(A.__table__.name, "foo")
+
def test_col_prop_attrs_associated_w_class_for_mapper_args(self):
from sqlalchemy import Column
import collections