JSON serializer doesn't handle None primary keys correctly (has tests.)
|Reported by:||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
comment:1 Changed 9 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|