marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

Why is `ordered=True` not the default for Schemas?

Open mkmoisen opened this issue 1 year ago • 1 comments

In order to iterate over a schema's fields in the order in which it was defined, you have to add a class Meta: ordered=True.

from marshmallow import Schema, fields

class FooSchema(Schema):
    id = fields.Int()
    bar_id = fields.Int()
    baz_id = fields.Int()
    creation_date = fields.DateTime()
    last_updated_date = fields.DateTime()
    
    class Meta:
        ordered = True

for field_name in FooSchema().fields:
    print(field_name)

Why isn't ordered=True the default?

mkmoisen avatar Jul 30 '22 16:07 mkmoisen

See #1744 (and #1896).

lafrech avatar Aug 08 '22 10:08 lafrech