JSON serializer doesn't handle None primary keys correctly (has tests.)
|Reported by:||phil.h.smith@…||Owned by:||pigletto|
|Severity:||Keywords:||json serialization primary key None null|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Seems conceptually similar to #2894.
If you serialize('json', [model]) a model with model.id == None, you will produce json containing "pk": "None" instead of "pk": null. The offending line seems to be in django.core.serializers.python.Serializer.end_object, around line 29, when str(obj._get_pk_val()) is called (or this is intentional and the generated "None" needs to be handled further down the line).
Test cases attached.
Change History (6)
Changed 9 years ago by phil.h.smith@…
comment:1 Changed 9 years ago by Simon G. <dev@…>
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:2 Changed 9 years ago by pigletto
- Owner changed from nobody to pigletto
- Status changed from new to assigned
Changed 9 years ago by pigletto
comment:3 Changed 9 years ago by pigletto
- Has patch set
- Triage Stage changed from Accepted to Ready for checkin