From ca58fa5d9338b6dfaa56b25c5affa369188a7086 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 25 Jun 2014 14:30:25 -0400 Subject: [PATCH] - 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 --- doc/build/changelog/changelog_09.rst | 14 ++++++++++++++ lib/sqlalchemy/ext/declarative/base.py | 2 +- test/ext/declarative/test_mixin.py | 25 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index b03e3f5b70..d82ab2dc50 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: 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'])) -- 2.47.3