ordered = True not respected
See original GitHub issueclass BaseSchema(Schema):
id = fields.Int(dump_only=True)
class LineItemSchema(BaseSchema):
name = fields.Str(attribute='label')
class CampaignSchema(BaseSchema):
name = fields.Str(attribute='campaign_name')
line_items = fields.Nested(LineItemSchema, many=True)
class Meta:
fields = ("id", "name", "line_items")
ordered = True
When I run: result = campaign_schema.dump(campaign) json.dumps(result.data)
I get this output:
{
"id": 1,
"line_items": [
{
"id": 1,
"name": "mpu"
},
{
"id": 3,
"name": "banner"
}
],
"name": "test"
}
I had a look in my debugger - think it’s something to do with that some of the field names are the same? Perhaps something to do with how ret is constructed here: https://github.com/marshmallow-code/marshmallow/blob/dev/marshmallow/schema.py#L729
Let me know if I’m missing something in my config somewhere!
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
ordered = True not respected. python + marshmallow + Flask
looks like property ordered=True on ChildSchema class is not working I have been looking for that in some posts and looks like the...
Read more >Marshmallow not respecting ordered=True
I had a little fight with Marshmallow and the ordered=True in class Meta. When ordered=True is set the fields should be outputed in...
Read more >3.3.3: Reaction Order - Chemistry LibreTexts
This can be found by adding the reaction orders with respect to the reactants. ... The order of a reaction is not necessarily...
Read more >Pandas Sort: Your Guide to Sorting Data in Python - Real Python
To sort the DataFrame based on the values in a single column, you'll use .sort_values() . By default, this will return a new...
Read more >Column ordering and sorting not working on reload - DataTables
My DT code is below. $('table.tasks-index').dataTable({ "processing": true, "responsive": true, "lengthChange": true, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This also happens in flask-smorest 0.22.0. All you need to do is disable
JSON_SORT_KEYS
in your config, as @halfar-aspire mentioned.This has something to do with json.dumps. I traced it into that method and it is not respecting the OrderedDict at least in Python 3.5.1. If you are using Flask-Restful, this could be why: http://flask-restful-cn.readthedocs.org/en/latest/extending.html “Note If the application is running in debug mode (app.debug = True) and either sort_keys or indent are not declared in the RESTFUL_JSON configuration setting, Flask-RESTful will provide defaults of True and 4 respectively.”