#8549: Fields added via the extra() QuerySet modifier are not outputted when
QuerySet is run through serializer
-----------------------------------------------------+----------------------
 Reporter:  Jim Dalton <[EMAIL PROTECTED]>  |       Owner:  nobody    
   Status:  new                                      |   Milestone:            
Component:  Serialization                            |     Version:  SVN       
 Keywords:                                           |       Stage:  Unreviewed
Has_patch:  0                                        |  
-----------------------------------------------------+----------------------
 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.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8549>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to