Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19746 closed New feature (fixed)

Allowing serialization without 'pk'

Reported by: rafallo 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 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 3 years ago by slurms

  • Easy pickings set
  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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 3 years ago by slurms

  • Needs documentation unset
  • Needs tests unset

comment:4 Changed 3 years ago by haxoza

  • Triage Stage changed from Accepted to Ready for checkin

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

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

  • Resolution set to fixed
  • Status changed from new to closed

In 278dad5b411e3e2ba8b428f7761882424353dea7:

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

comment:6 Changed 3 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