#26291: loaddata cannot deserialize fixtures with forward references and natural
foreign keys
-------------------------------------+-------------------------------------
     Reporter:  inglesp              |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Core                 |                  Version:  1.9
  (Serialization)                    |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by timgraham):

 * needs_better_patch:   => 0
 * type:  Uncategorized => New feature
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> The following fixture cannot be deserialized, unless an Author object
> with name "John Steinbeck" already exists.  This is because when Django
> tries to deserialize the first object, it tries to load an Author with
> name "John Steinbeck", which fails.
>

> {{{
> [
>   {
>     "model": "app.book",
>     "fields": {
>       "title": "East Of Eden",
>       "author": ["John Steinbeck"]
>     }
>   },
>   {
>     "model": "app.author",
>     "fields": {
>       "name": "John Steinbeck",
>       "date_of_birth": "1902-02-27"
>     }
>   }
> ]
> }}}
>
> This problem is avoidable with careful ordering of fixture loading, but
> is still a problem with fixtures that have circular references.
>
> I have a proposed fix: see PR 6221

New description:

 The following fixture cannot be deserialized, unless an Author object with
 name "John Steinbeck" already exists.  This is because when Django tries
 to deserialize the first object, it tries to load an Author with name
 "John Steinbeck", which fails.


 {{{
 [
   {
     "model": "app.book",
     "fields": {
       "title": "East Of Eden",
       "author": ["John Steinbeck"]
     }
   },
   {
     "model": "app.author",
     "fields": {
       "name": "John Steinbeck",
       "date_of_birth": "1902-02-27"
     }
   }
 ]
 }}}

 This problem is avoidable with careful ordering of fixture loading, but is
 still a problem with fixtures that have circular references.

 I have a proposed fix: see [https://github.com/django/django/pull/6221 PR
 6221]

--

Comment:

 The proposed code looks rather complicated. What you are saying is that
 [https://docs.djangoproject.com/en/dev/topics/serialization/#dependencies-
 during-serialization the instructions about fixture ordering] aren't
 sufficient due to the possibility of circular references, correct? Could
 you give an example of that to motivate the feature a bit more?

--
Ticket URL: <https://code.djangoproject.com/ticket/26291#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.795268dfcbd74cd1536cdff31e8d3643%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to