Skip to content

values() returns wrong results when used with list values (JSONField) #196

@Lambda14

Description

@Lambda14

If you create model with list in attribute

MockSet(MockModel(list_attr=pytest.pydict()))

then tries to

self.model.objects.filter(id=_id).values("list_attr").first()
> {'list_attr': 'nAvOpyEVAoNGnVZQUqLU'}

if call attribute directly
self.model.objects.filter(id=_id).first().list_attr
it returns full list
['nAvOpyEVAoNGnVZQUqLU', '[email protected]', 3350, datetime.datetime(2002, 6, 18, 3, 24, 51), ...]

for some reason in _item_values method dict transforms into list[dict] here
item_values.append({k: v[i] for k, v in field_buckets.items()})

What is this behavior for?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions