lovasoa / marshmallow_dataclass

Automatic generation of marshmallow schemas from dataclasses.

Home Page:https://lovasoa.github.io/marshmallow_dataclass/html/marshmallow_dataclass.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dataclasses get unsorted after deserialization

Shadowhnr opened this issue · comments

Hi I'm trying to get an ordered response according to my input, and when the data gets converted from dict to the dataclass with schema.load(dict), the results get thrown out of order within the list. Prior to the deserialization, the list of dicts was ordered by count descending. I tried also setting the variable JSON_SORT_KEYS to True, but to no avail.

marshmallow | 3.15.0
marshmallow-dataclass | 8.5.8
marshmallow-enum | 1.5.1
Flask | 1.1.4
Python | 3.8

@DataClass(order=True)
class HouseItem:
class Meta:
ordered = True
count: int
value: str

@DataClass(order=True)
class House:
class Meta:
ordered = True
results: List[HouseItem] = field(default_factory=list)

After I deserialize them:

result = [  { "count": 12,
        "value": "sink",
           },
    {
        "count": 544,
        "value": "plug",
        },
 {

"count": 4,
"value": "bed",
}

        ]