-
-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when passing custom parameter in Nested schema #2306
Comments
I'm unable to reproduce that error. from marshmallow import Schema, fields, post_dump
class SchemaA(Schema):
field = fields.Dict(
required=False,
load_default={},
)
def __init__(self, *args, **kwargs):
self.replace_field_with_string = (
kwargs.pop('replace_field_with_string', False))
super().__init__(*args, **kwargs)
@post_dump
def convert_field_to_string(self, data, **kwargs):
if (self.replace_field_with_string and 'field' in data
and isinstance(data['field'], dict)):
data['field'] = data['field'].get('string', '')
return data
class SchemaB(Schema):
data = fields.List(
fields.Nested(lambda: SchemaA(replace_field_with_string=True)),
required=True,
dump_only=True,
)
data = {'data': [{'field': {'string': 'bar'}}]}
schema = SchemaB()
x = schema.dump(data)
print(x)
# {'data': [{'field': 'bar'}]} |
Hm that is interesting. I apologize if I am not explaining this right, but I tried tracing this issue in the debugger and the first thing I noticed was that in |
@qurram-zaheer do you have an updated code sample that produces the error? |
Hello, I have 2 schemas set up something like this:
Is there something incorrect in this code? Because when I do something like this:
I get
dictionary update sequence element #0 has length 1; 2 is required
errorThe text was updated successfully, but these errors were encountered: