#25693: Data loss if a ManyToManyField is shadowed by Prefetch
-------------------------------------+-------------------------------------
     Reporter:  Ian-Foote            |                    Owner:  Ian-Foote
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Ian-Foote:

Old description:

> With two models:
>
> {{{#!python
> class Book(Model):
>     name = CharField(max_length=100)
>
> class Author(Model):
>     books = ManyToManyField(Book)
> }}}
>
> it is possible to create a prefetch query that loses data from
> Author.books:
>
> {{{#!python
> poems = Book.objects.filter(name='Poems')
> Author.objects.prefetch_related(
>     Prefetch('books', queryset=poems, to_attr='books'),
> )
> }}}
>
> When this queryset is evaluated, each Author's books is overridden by the
> poems queryset.

New description:

 With two models:

 {{{#!python
 class Book(Model):
     name = CharField(max_length=100)

 class Author(Model):
     books = ManyToManyField(Book)
 }}}

 it is possible to create a prefetch query that loses data from
 {{{Author.books}}}:

 {{{#!python
 poems = Book.objects.filter(name='Poems')
 Author.objects.prefetch_related(
     Prefetch('books', queryset=poems, to_attr='books'),
 )
 }}}

 When this queryset is evaluated, each Author's {{{books}}} is overridden
 by the {{{poems}}} queryset.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25693#comment:2>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.06758276ffcb0999e7095e7f5f958d08%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to