home / django_tickets / tickets

tickets: 8549

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8549 2008-08-26 00:38:30 2008-08-26 00:41:52 2022-03-06 03:42:33.293323 Unreviewed closed Core (Serialization)     dev duplicate Fields added via the extra() QuerySet modifier are not outputted when QuerySet is run through serializer It appears that when you add a field via the {{{extra()}}} method on a {{{QuerySet}}}, that field is not made available to you when you run the {{{QuerySet}}} through the serializer. I am running django version 1.0-beta_1-SVN-8539. The context in which I discovered this bug, brief: I set a custom field using extra() so that i could order results by a distance form a given longitude/latitude pair. The custom field uses MySQL numeric functions. Example looks like: {{{ entries = Entry.objects.extra(select={'distance': "SQRT(POW((locations.lat-%s),2) + POW((locations.lon-%s),2))"}, select_params=(str(centerLat), str(centerLng))) entries = entries.extra(order_by = ['distance'])[:5] }}} This works. {{{entries[0].distance}}} returns a float correctly, for example. The bug arises when this {{{QuerySet}}} is serialized and output, as follows: {{{ from django.core import serializers json_serializer = serializers.get_serializer("json")() json_serializer.serialize(entries, ensure_ascii=False, stream=response) }}} The response stream does NOT include the distance attribute, though all other attributes of the model are set. Even explicitly setting the distance attribute in the fields argument of {{{serialize()}}} does not include the distance attribute. I tried changing the serializer to xml to see if it was an artifact of json, but still the attribute was not included. I did confirm that the attribute exists on the {{{QuerySet}}} itself I tried searching on this bug and I posted this on django-users and found nothing. My apologies if this is not a bug or its been reported elsewhere. I hope this is useful. nobody Jim Dalton <jim.dalton@furrybrains.com>   0 0 0 0 0 0
Powered by Datasette · Queries took 0.876ms