#29472: Natural key not serializing for primary_key OneToOneField
-------------------------------------+-------------------------------------
Reporter: Ferd Snidely | Owner: nobody
Type: Bug | Status: new
Component: Core | Version: 2.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Ferd Snidely:
Old description:
> 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.product3",
> "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.
New description:
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29472#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.ff6bf0f78740f8706ce3abedf894e769%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.