﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8549	Fields added via the extra() QuerySet modifier are not outputted when QuerySet is run through serializer	Jim Dalton <jim.dalton@…>	nobody	"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."		closed	Core (Serialization)	dev		duplicate			Unreviewed	0	0	0	0	0	0
