Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19746 closed New feature (fixed)

Allowing serialization without 'pk'

Reported by: Rafał Jagoda Owned by: nobody
Component: Core (Serialization) Version: dev
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

Description

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/python.py django/core/serializers/python.py
index 5e07e2a..cdfac50 100644
--- django/core/serializers/python.py
+++ django/core/serializers/python.py
@@ -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 = {Model._meta.pk.attname: Model._meta.pk.to_python(d["pk"])}
+        data = {Model._meta.pk.attname: Model._meta.pk.to_python(d.get("pk", None))}
         m2m_data = {}
         model_fields = Model._meta.get_all_field_names()

Do I have to write proper documentation?

Change History (6)

comment:1 by Russell Keith-Magee, 12 years ago

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 by Nick Sandford, 12 years ago

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 by Nick Sandford, 12 years ago

Needs documentation: unset
Needs tests: unset

comment:4 by Przemek Lewandowski, 12 years ago

Triage Stage: AcceptedReady for checkin

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

comment:5 by Nick Sandford <nick@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 278dad5b411e3e2ba8b428f7761882424353dea7:

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

comment:6 by Florian Apolloner <florian@…>, 12 years ago

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