summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-09 14:21:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-09 14:21:40 -0400
commitd84ae4f75468fea6b3345c1275d6a472d0cf7c5f (patch)
tree69ae37b83fcbd196cb4cb9424c7f407ebf7acf21 /test/ext
parent70a173d22b520b41acc8624f1a1d6c8c456412f7 (diff)
downloadsqlalchemy-d84ae4f75468fea6b3345c1275d6a472d0cf7c5f.tar.gz
Fixed indirect regression regarding :func:`.has_inherited_table`,
where since it considers the current class' ``__table__``, was sensitive to when it was called. This is 0.7's behavior also, but in 0.7 things tended to "work out" within events like ``__mapper_args__()``. :func:`.has_inherited_table` now only considers superclasses, so should return the same answer regarding the current class no matter when it's called (obviously assuming the state of the superclass). [ticket:2656]
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/declarative/test_inheritance.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/ext/declarative/test_inheritance.py b/test/ext/declarative/test_inheritance.py
index ab78cc3e2..f0372e8ee 100644
--- a/test/ext/declarative/test_inheritance.py
+++ b/test/ext/declarative/test_inheritance.py
@@ -14,7 +14,8 @@ from sqlalchemy.orm import relationship, create_session, class_mapper, \
Session
from sqlalchemy.testing import eq_
from sqlalchemy.util import classproperty
-from sqlalchemy.ext.declarative import declared_attr, AbstractConcreteBase, ConcreteBase
+from sqlalchemy.ext.declarative import declared_attr, AbstractConcreteBase, \
+ ConcreteBase, has_inherited_table
from sqlalchemy.testing import fixtures
Base = None
@@ -1112,6 +1113,46 @@ class ConcreteInhTest(_RemoveListeners, DeclarativeTestBase):
'concrete':True}
self._roundtrip(Employee, Manager, Engineer, Boss)
+
+ def test_has_inherited_table_doesnt_consider_base(self):
+ class A(Base):
+ __tablename__ = 'a'
+ id = Column(Integer, primary_key=True)
+
+ assert not has_inherited_table(A)
+
+ class B(A):
+ __tablename__ = 'b'
+ id = Column(Integer, ForeignKey('a.id'), primary_key=True)
+
+ assert has_inherited_table(B)
+
+ def test_has_inherited_table_in_mapper_args(self):
+ class Test(Base):
+ __tablename__ = 'test'
+ id = Column(Integer, primary_key=True)
+ type = Column(String(20))
+
+ @declared_attr
+ def __mapper_args__(cls):
+ if not has_inherited_table(cls):
+ ret = {
+ 'polymorphic_identity': 'default',
+ 'polymorphic_on': cls.type,
+ }
+ else:
+ ret = {'polymorphic_identity': cls.__name__}
+ return ret
+
+ class PolyTest(Test):
+ __tablename__ = 'poly_test'
+ id = Column(Integer, ForeignKey(Test.id), primary_key=True)
+
+ configure_mappers()
+
+ assert Test.__mapper__.polymorphic_on is Test.__table__.c.type
+ assert PolyTest.__mapper__.polymorphic_on is Test.__table__.c.type
+
def test_ok_to_override_type_from_abstract(self):
class Employee(AbstractConcreteBase, Base, fixtures.ComparableEntity):
pass