Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #89 from sergray/master
Browse files Browse the repository at this point in the history
Fix overriding of schema class
  • Loading branch information
SVilgelm authored Jul 9, 2020
2 parents e4f1f61 + cc687de commit 8fa667e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion marshmallow_objects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __new__(mcs, name, parents, dct):
parent_schemas = []
if parents:
for parent in parents:
if issubclass(parent, Model):
if issubclass(parent, Model) and parent != Model:
parent_schemas.append(parent.__schema_class__)
parent_schemas = parent_schemas or [cls.__schema_class__ or marshmallow.Schema]
schema_class = type(name + "Schema", tuple(parent_schemas), schema_fields)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class MultiInheritance(A, B, C):
pass


class CustomSchema(marshmallow.Schema):
def custom_method(self):
pass


class D(marshmallow.Model):
__schema_class__ = CustomSchema


def serialize_context_field(obj, context=None):
return obj.test_field == context["value"]

Expand Down Expand Up @@ -113,6 +122,9 @@ def test_handle_error(self):
id(MultiInheritance.handle_error), id(MultiInheritance.__schema_class__.handle_error),
)

def test_schema_class_override(self):
self.assertTrue(issubclass(D.__schema_class__, CustomSchema), D.__schema_class__.__bases__)


class TestModel(unittest.TestCase):
def test_tag_field(self):
Expand Down

0 comments on commit 8fa667e

Please sign in to comment.