#24951: Error deleting from table with Foreign Key being Primary Key at the same
point
----------------------------------------------+--------------------
     Reporter:  grumbler                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.8
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 Problem occurs, when trying to issue delete on queryset for a table like
 this:
 {{{
 class Derivative(models.Model):
     spot = models.OneToOneField(Spot, primary_key=True)
     flag = models.BooleanField(default=True)

 Derivative.objects.filter(spot__name__icontains='name').delete()
 }}}

 Result is:
 AssertionError: Can only delete from one table at a time.

 However, if we have simple table like this:
 {{{
 class SimpleDerivative(models.Model):
     spot = models.OneToOneField(Spot)
     flag = models.BooleanField(default=True)
 }}}
 than there is no problem. Note, there is no primary_key for spot here.

 Problem does not exist for Django 1.6 (I didn't check for previous
 versions)
 And persits in 1.7 and 1.8

 There is changed code between versions in:
 django/db/models/sql/subqueries.py - DeleteQuery.delete_qs

 right before the last line self.tables contains two tables, which leads to
 assertion error.

 I provided sample project to reproduce issue -
 https://github.com/grumbler/django_delete_issue
 Simply run the tests with the appropriate Django version  installed.

--
Ticket URL: <https://code.djangoproject.com/ticket/24951>
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/051.ccf971701db5dbddea63c254ce9bac54%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to