﻿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
29472	Natural key not serializing for primary_key OneToOneField	Ferd Snidely	nobody	"Serializing a model using a natural key that has a OneToOneField primary_key or parent_link fails to include the natural_key.

The problem occurs when serializing with use_natural_primary_keys=True,
and use_natural_foreign_keys=True. The parent_link field is not included
in the 'fields' structure in the json format (fails similarly for xml as
well).

    Equivalent to this unanswered stackoverflow:
    https://stackoverflow.com/questions/28702215/natural-key-serialize-django-model-with-one-to-one-field-as-primary-key

I have an example project at [https://github.com/fsnidely/serialtest github/fsnidely/serialtest], which has an example model with tests.

An example of the expected serialized model with its natural_key ('thing'):

{{{
    {
        ""model"": ""sandbox.product"",
        ""fields"": {
            ""thing"": [
                ""F-A""
            ],
            ""prod_secs"": 42,
            ""low_level"": -1
        }
    },
}}}

What is actually returned by `serializers.serialize(""json"", ...` or `python manage.py dumpdata ...`:

{{{
    {
        ""model"": ""sandbox.product"",
        ""fields"": {
            ""prod_secs"": 42,
            ""low_level"": -1
        }
    }

}}}

Notice that there is no PK or NK ('thing') for the object.

A simple parent model and child model inheriting parent model with a natural_key() is sufficient to reproduce the problem.

This problem appears to have existed in prior versions of Django as the referenced StackOverflow issue is over 3 years old.
"	Bug	closed	Core (Serialization)	2.0	Normal	duplicate			Unreviewed	0	0	0	0	0	0
