From: Mike Bayer Date: Wed, 25 Jun 2014 18:30:25 +0000 (-0400) Subject: - Fixed bug when the declarative ``__abstract__`` flag was not being X-Git-Tag: rel_0_9_7~82 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ad0ddca4c9251698fd2179d6c25954ab147524e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug when the declarative ``__abstract__`` flag was not being distinguished for when it was actually the value ``False``. The ``__abstract__`` flag needs to acutally evaluate to a True value at the level being tested. fixes #3097 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 38d71b2ab8..691322a8fc 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -10,6 +10,20 @@ .. include:: changelog_07.rst :start-line: 5 +.. changelog:: + :version: 0.9.7 + :released: + + .. change:: + :tags: bug, declarative + :tickets: 3097 + :versions: 1.0.0 + + Fixed bug when the declarative ``__abstract__`` flag was not being + distinguished for when it was actually the value ``False``. + The ``__abstract__`` flag needs to acutally evaluate to a True + value at the level being tested. + .. changelog:: :version: 0.9.6 :released: June 23, 2014 diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py index 0e68faa03d..308c096919 100644 --- a/lib/sqlalchemy/ext/declarative/base.py +++ b/lib/sqlalchemy/ext/declarative/base.py @@ -56,7 +56,7 @@ def _as_declarative(cls, classname, dict_): @event.listens_for(mapper, "before_configured") def go(): cls.__declare_first__() - if '__abstract__' in base.__dict__: + if '__abstract__' in base.__dict__ and base.__abstract__: if (base is cls or (base in cls.__bases__ and not _is_declarative_inherits) ): diff --git a/test/ext/declarative/test_mixin.py b/test/ext/declarative/test_mixin.py index dab6275966..d3c2ff9824 100644 --- a/test/ext/declarative/test_mixin.py +++ b/test/ext/declarative/test_mixin.py @@ -115,7 +115,6 @@ class DeclarativeMixinTest(DeclarativeTestBase): eq_(MyModelA.__table__.c.foo.type.__class__, String) eq_(MyModelB.__table__.c.foo.type.__class__, Integer) - def test_not_allowed(self): class MyMixin: @@ -1279,3 +1278,27 @@ class DeclarativeMixinPropertyTest(DeclarativeTestBase): def test_relationship_primryjoin(self): self._test_relationship(True) + +class AbstractTest(DeclarativeTestBase): + def test_abstract_boolean(self): + + class A(Base): + __abstract__ = True + __tablename__ = 'x' + id = Column(Integer, primary_key=True) + + class B(Base): + __abstract__ = False + __tablename__ = 'y' + id = Column(Integer, primary_key=True) + + class C(Base): + __abstract__ = False + __tablename__ = 'z' + id = Column(Integer, primary_key=True) + + class D(Base): + __tablename__ = 'q' + id = Column(Integer, primary_key=True) + + eq_(set(Base.metadata.tables), set(['y', 'z', 'q']))