我有 3 个带有嵌套字段的棉花糖模式,它们形成了一个依赖循环/三角形。如果我使用双向嵌套的样板,我似乎没有问题。
from marshmallow import Schema, fields
class A(Schema):
id = fields.Integer()
b = fields.Nested('B')
class B(Schema):
id = fields.Integer()
c = fields.Nested('C')
class C(Schema):
id = fields.Integer()
a = fields.Nested('A')
但是,我有自己的 fields.Nested 薄子类,如下所示:
from marshmallow import fields
class NestedRelationship(fields.Nested):
def __init__(self, nested,
include_data=True,
**kwargs):
super(NestedRelationship, self).__init__(nested, **kwargs)
self.schema.is_relationship = True
self.schema.include_relationship_data = include_data
我将每个模式更改为使用 NestedRelationship 而不是本机Nested
类型,我得到:
marshmallow.exceptions.RegistryError: Class with name 'B' was not found. You may need to import the class.
NestedRelationship 是一个相对薄的子类,我对行为的差异感到惊讶。我在这里做错了吗?我不恰当地称呼超级吗?