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

Commit 8fa667e

Browse files
authored
Merge pull request #89 from sergray/master
Fix overriding of schema class
2 parents e4f1f61 + cc687de commit 8fa667e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

marshmallow_objects/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __new__(mcs, name, parents, dct):
5050
parent_schemas = []
5151
if parents:
5252
for parent in parents:
53-
if issubclass(parent, Model):
53+
if issubclass(parent, Model) and parent != Model:
5454
parent_schemas.append(parent.__schema_class__)
5555
parent_schemas = parent_schemas or [cls.__schema_class__ or marshmallow.Schema]
5656
schema_class = type(name + "Schema", tuple(parent_schemas), schema_fields)

tests/test_models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class MultiInheritance(A, B, C):
5555
pass
5656

5757

58+
class CustomSchema(marshmallow.Schema):
59+
def custom_method(self):
60+
pass
61+
62+
63+
class D(marshmallow.Model):
64+
__schema_class__ = CustomSchema
65+
66+
5867
def serialize_context_field(obj, context=None):
5968
return obj.test_field == context["value"]
6069

@@ -113,6 +122,9 @@ def test_handle_error(self):
113122
id(MultiInheritance.handle_error), id(MultiInheritance.__schema_class__.handle_error),
114123
)
115124

125+
def test_schema_class_override(self):
126+
self.assertTrue(issubclass(D.__schema_class__, CustomSchema), D.__schema_class__.__bases__)
127+
116128

117129
class TestModel(unittest.TestCase):
118130
def test_tag_field(self):

0 commit comments

Comments
 (0)