#13252: Use the natural key instead of the primary key when serializing
------------------------------------+---------------------------------------
          Reporter:  SmileyChris    |         Owner:  mtredinnick
            Status:  reopened       |     Milestone:             
         Component:  Serialization  |       Version:  SVN        
        Resolution:                 |      Keywords:             
             Stage:  Accepted       |     Has_patch:  1          
        Needs_docs:  0              |   Needs_tests:  0          
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Comment (by mrmachine):

 I've just updated the patch after feedback from freakboy3742 on IRC.

 The new patch adds `--natural-foreign` and `--natural-primary` options to
 the `dumpdata` management command, maps the `-n` and `--natural` options
 to `--natural-foreign` and adds a note in the documentation that the old
 options are deprecated. This should retain backwards compatibility with
 anyone who was depending on data dumped with natural keys still containing
 a `pk` field for models that support natural keys. It also adds the
 corresponding `use_natural_foreign_keys` and `use_natural_primary_keys`
 arguments to `serializers.serialize()` and maps `use_natural_keys` to
 `use_natural_foreign_keys`.

 I've left a comment in the source code where I think we should probably
 raise a deprecation warning (but not actually raised it) if that ends up
 being the desired behaviour.

 One quirk is that the code beginning at line 30 in
 django/core/serializers/python.py appears to affect the order of fields in
 serialized output depending on how the data dict is constructed, even
 though the resulting data dict contains the same data. If I first create
 the data dict with `model` and `fields` items and then conditionally add a
 `pk` item (as the old patch did), then the serialized output is different
 to when I create the data dict with `model`, `pk` and `fields` items.
 Rather than change a tonne of hard coded tests, I construct the data dict
 the same way that it would have been before the patch which results in a
 couple of duplicated lines of code.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13252#comment:11>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to