it's me again, now with a marshmallow question, I have the following structure:
route.py
@models.response(ParentSchema())
def get(args, model_id):
return {"response": {"a": [{"data": "a"}], "b": [{"data": "a"}], "c": [{"data": "a"}], "d": [{"data": "a"}]}}
then this is my schemas file schema.py
class SubChildSchema(Schema):
data = fields.Str(description="Model's name")
class ChildSchema(Schema):
class Meta:
ordered = True
a = fields.Nested(SubChildSchema, many=True)
b = fields.Nested(SubChildSchema, many=True)
c = fields.Nested(SubChildSchema, many=True)
d = fields.Nested(SubChildSchema, many=True)
class ParentSchema(Schema):
response = fields.Nested(ChildSchema)
it suppose that in the response I should get a sorted response like:
{
"response": {
"a": [
{
"data": "a"
}
],
"b": [
{
"data": "a"
}
],
"c": [
{
"data": "a"
}
],
"d": [
{
"data": "a"
}
]
}
}
but instead of that I am receiving
{
"response": {
"b": [
{
"data": "a"
}
],
"c": [
{
"data": "a"
}
],
"d": [
{
"data": "a"
}
],
"a": [
{
"data": "a"
}
]
}
}
looks like property ordered=True on ChildSchema class is not working I have been looking for that in some posts and looks like the issue happens when you mix Nested fields and the ordered property.
This is my stack
flask-marshmallow==0.14.0
marshmallow==2.21.0
marshmallow-sqlalchemy==0.23.1