﻿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
15488	Behaviour natural keys differ between json and xml serializers	sueastside@…	nobody	"Behaviour natural keys differ between json and xml serializers

Using a single value for the natural key.

Consider the following code:
{{{
#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  class A(models.Model):
    name = models.CharField(unique=True) 
    def natural_key(self):
      return self.name

  class B(models.Model):
    a = models.ForeignKey(A)
  }}}
}}}

Which results in some nice json:
{{{
    ""pk"": 1, 
    ""model"": ""models.b"", 
    ""fields"": {
      ""a"": ""hello""
     }
}}}

but goes wrong in XML:
{{{
  <object pk=""1"" model=""models.b"">
    <field to=""models.a"" name=""a"" rel=""ManyToOneRel"">
      <natural>h</natural>
      <natural>e</natural>
      <natural>l</natural>
      <natural>l</natural>
      <natural>o</natural>
    </field>
  </object>
}}}


Ofcourse a tuple can be returned from natural_key(), but that results in:
{{{
    ""pk"": 1, 
    ""model"": ""models.b"", 
    ""fields"": {
      ""a"": [""hello""]
     }
}}}

Which is kind of annoying.

Attached is a small patch draft.


Thank you for your time."		closed	Core (Serialization)	dev		invalid	serialization, natural key, xml, json		Unreviewed	1	0	0	0	0	0
