From 5f831535c8834c7950dafdacb3da062727f182e5 Mon Sep 17 00:00:00 2001 From: Simon Hewitt Date: Wed, 12 Oct 2016 11:26:22 -0700 Subject: [PATCH] allow abstract subclasses of SQLAlchemyObjectType --- graphene_sqlalchemy/tests/test_types.py | 12 ++++++++++++ graphene_sqlalchemy/types.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index 83bdc263..de53bee5 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -74,3 +74,15 @@ def test_object_type(): assert issubclass(Human, ObjectType) assert list(Human._meta.fields.keys()) == ['id', 'headline', 'reporter_id', 'reporter', 'pub_date'] assert is_node(Human) + + +def test_abstract_subclass(): + registry = Registry() + + class AbstractSubclass(SQLAlchemyObjectType): + class Meta: + registry = registry + abstract = True + + assert issubclass(AbstractSubclass, SQLAlchemyObjectType) + assert len(registry._registry) == 0 diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index 70729ed6..9b037b01 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -69,7 +69,8 @@ class SQLAlchemyObjectTypeMeta(ObjectTypeMeta): def __new__(cls, name, bases, attrs): # Also ensure initialization is only performed for subclasses of Model # (excluding Model class itself). - if not is_base_type(bases, SQLAlchemyObjectTypeMeta): + if not is_base_type(bases, SQLAlchemyObjectTypeMeta) or \ + ('Meta' in attrs and getattr(attrs['Meta'], 'abstract', False)): return type.__new__(cls, name, bases, attrs) options = Options(