Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#19746 closed New feature (fixed)

Allowing serialization without 'pk'

Reported by: Rafał Jagoda Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


Currently, if I want to use python serializer to deserialize data, I have to put 'pk' or proper pk.attname value in object in object_list.
I suggest to allow deserialize object without 'pk' attribute and allow DB to create 'pk' value.

diff --git django/core/serializers/ django/core/serializers/
index 5e07e2a..cdfac50 100644
--- django/core/serializers/
+++ django/core/serializers/
@@ -88,7 +88,7 @@ def Deserializer(object_list, **options):
     for d in object_list:
         # Look up the model and starting build a dict of data for it.
         Model = _get_model(d["model"])
-        data = {["pk"])}
+        data = {"pk", None))}
         m2m_data = {}
         model_fields = Model._meta.get_all_field_names()

Do I have to write proper documentation?

Change History (6)

comment:1 Changed 8 years ago by Russell Keith-Magee

Procedurally - if you want a patch to be taken seriously, you need to provide documentation *and* tests. We don't accept any new feature without both.

This appears to be very closely related to #11486; is this a case where you're requesting a feature that already exists, or is it a specific failure in the Python serializer? The Python serializer is an internal mechanism, and not intended as a public serializer, so if you want to add this feature, you'll need to demonstrate how it affects the public serializers, or explain why the Python serializer should gain this new feature.

comment:2 Changed 8 years ago by Nick Sandford

Easy pickings: set
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Looks like it affects not just the Python deserializer, but also the JSON and YAML deserializers too, as they both use the Python deserializer. If we allow deserializing XML without a pk attribute, it stands to reason that the others should also follow suit?

comment:3 Changed 8 years ago by Nick Sandford

Needs documentation: unset
Needs tests: unset

comment:4 Changed 8 years ago by Przemek Lewandowski

Triage Stage: AcceptedReady for checkin

Code and tests work good. Documentation is updated with version changed tag for 1.6.

comment:5 Changed 8 years ago by Nick Sandford <nick@…>

Resolution: fixed
Status: newclosed

In 278dad5b411e3e2ba8b428f7761882424353dea7:

Fixed #19746 -- Allow deserialization of pk-less data

comment:6 Changed 8 years ago by Florian Apolloner <florian@…>

In 4506ae0497d388f8bc118b9f6f916a5da48d599a:

Merge pull request #717 from slurms/ticket_19746

Fixed #19746 -- Allow deserialization of pk-less data

Note: See TracTickets for help on using tickets.
Back to Top