#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 , 12 years ago
comment:2 by , 12 years ago
Easy pickings: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → 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 by , 12 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Added a pull request here: https://github.com/django/django/pull/717
comment:4 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Code and tests work good. Documentation is updated with version changed tag for 1.6.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.