Opened 16 years ago
Closed 16 years ago
#10412 closed (duplicate)
queryset.values(*fields) should return field instances, not raw values
Description ¶
Currently, the values(*fields) method of queryset objects returns the raw database data, not what fields’ to_python would have returned. For many kinds of fields it is useless. For example, a result of the values() invocation can look like
[{"id": 42, "is_interesting": 1, "photo": "some/path/image.jpg"}]
while it could have been something like
[{"id": 42, "is_interesting": True, "photo": ImageFieldFile("some/path/image.jpg")}]
The database only holds the data, not its interpretation. Observe how the data for the image field is useless without knowing upload_to, and (for MySQL) Django can’t convert 1 to True because it doesn’t know that the field is in fact a BooleanField (cf. “wontfix” #7190). And isn’t it counter-intuitive for qs.all().values()[ 0 ][ "something" ] to differ from qs.all()[ 0 ].something?
Fixing this will also allow to fix #7190 once and for all, a bug into which I ran as recently as today.
Regarding documentation, it doesn’t document what qs.values().values() are at all, so nothing to break.
Duplicate of #9619.