Re: [Django] #28551: Exclude query on M2M field with F() fails

2017-09-04 Thread Django
#28551: Exclude query on M2M field with F() fails
-+-
 Reporter:  daishi   |Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  duplicate
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Tim Graham):

 * status:  new => closed
 * resolution:   => duplicate


-- 
Ticket URL: 
Django 
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/064.f8496e03f05725342a14f63b362d921b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28551: Exclude query on M2M field with F() fails

2017-09-04 Thread Django
#28551: Exclude query on M2M field with F() fails
-+-
 Reporter:  daishi   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  1.11
  (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
-+-
Changes (by Tim Graham):

 * type:  Uncategorized => Bug
 * component:  Uncategorized => Database layer (models, ORM)


Old description:

> Given the following models:
> {{{
> class A(models.Model):
> pass
>
> class B(models.Model):
> a = models.ManyToManyField(A)
>
> class C(models.Model):
> a = models.ForeignKey(A)
> b = models.ForeignKey(B)
> }}}
> The following test:
> {{{
> a1 = A()
> a1.save()
> a2 = A()
> a2.save()
> b1 = B()
> b1.save()
> b1.a.add(a1)
> b1.save()
> b2 = B()
> b2.save()
> b2.a.add(a2)
> b2.save()
> c1 = C(a=a1, b=b1)
> c1.save()
> c2 = C(a=a1, b=b2)
> c2.save()
> self.assertEqual(1, C.objects.filter(b__a=F('a')).count())
> self.assertEqual(1, C.objects.exclude(b__a=F('a')).count())
> }}}
> Fails with the following error:
> {{{
> OperationalError: no such column: U2.id
> }}}
> The SQL generated by Django for the `C.objects.exclude(b__a=F('a'))`
> fragment is logged as:
> {{{
> SELECT "a_c"."id", "a_c"."a_id", "a_c"."b_id" FROM "a_c" WHERE NOT
> ("a_c"."b_id" IN (SELECT U3."b_id" AS Col1 FROM "a_c" U0 INNER JOIN
> "a_b_a" U3 ON (U2."id" = U3."b_id") WHERE U3."a_id" = (U0."a_id"))) LIMIT
> 21; args=()
> }}}
> As suggested in the error, the `U2` join table does not seem to be
> defined in the generated query.

New description:

 Given the following models:
 {{{
 class A(models.Model):
 pass

 class B(models.Model):
 a = models.ManyToManyField(A)

 class C(models.Model):
 a = models.ForeignKey(A)
 b = models.ForeignKey(B)
 }}}
 The following test:
 {{{
 a1 = A()
 a1.save()
 a2 = A()
 a2.save()
 b1 = B()
 b1.save()
 b1.a.add(a1)
 b1.save()
 b2 = B()
 b2.save()
 b2.a.add(a2)
 b2.save()
 c1 = C(a=a1, b=b1)
 c1.save()
 c2 = C(a=a1, b=b2)
 c2.save()
 self.assertEqual(1, C.objects.filter(b__a=F('a')).count())
 self.assertEqual(1, C.objects.exclude(b__a=F('a')).count())
 }}}
 Fails with the following error:
 {{{
 OperationalError: no such column: U2.id
 }}}
 The SQL generated by Django for the `C.objects.exclude(b__a=F('a'))`
 fragment is logged as:
 {{{
 SELECT "a_c"."id", "a_c"."a_id", "a_c"."b_id" FROM "a_c" WHERE NOT
 ("a_c"."b_id" IN (SELECT U3."b_id" AS Col1 FROM "a_c" U0 INNER JOIN
 "a_b_a" U3 ON (U2."id" = U3."b_id") WHERE U3."a_id" = (U0."a_id"))) LIMIT
 21; args=()
 }}}
 As suggested in the error, the `U2` join table does not seem to be defined
 in the generated query.

--

Comment:

 Looks like a duplicate of #21703.

-- 
Ticket URL: 
Django 
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/064.354eafc174e07db15d4e7fafdf170ee1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #28551: Exclude query on M2M field with F() fails

2017-08-30 Thread Django
#28551: Exclude query on M2M field with F() fails
-+
   Reporter:  daishi |  Owner:  nobody
   Type:  Uncategorized  | Status:  new
  Component:  Uncategorized  |Version:  1.11
   Severity:  Normal |   Keywords:
   Triage Stage:  Unreviewed |  Has patch:  0
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+
 Given the following models:
 {{{
 class A(models.Model):
 pass

 class B(models.Model):
 a = models.ManyToManyField(A)

 class C(models.Model):
 a = models.ForeignKey(A)
 b = models.ForeignKey(B)
 }}}
 The following test:
 {{{
 a1 = A()
 a1.save()
 a2 = A()
 a2.save()
 b1 = B()
 b1.save()
 b1.a.add(a1)
 b1.save()
 b2 = B()
 b2.save()
 b2.a.add(a2)
 b2.save()
 c1 = C(a=a1, b=b1)
 c1.save()
 c2 = C(a=a1, b=b2)
 c2.save()
 self.assertEqual(1, C.objects.filter(b__a=F('a')).count())
 self.assertEqual(1, C.objects.exclude(b__a=F('a')).count())
 }}}
 Fails with the following error:
 {{{
 OperationalError: no such column: U2.id
 }}}
 The SQL generated by Django for the `C.objects.exclude(b__a=F('a'))`
 fragment is logged as:
 {{{
 SELECT "a_c"."id", "a_c"."a_id", "a_c"."b_id" FROM "a_c" WHERE NOT
 ("a_c"."b_id" IN (SELECT U3."b_id" AS Col1 FROM "a_c" U0 INNER JOIN
 "a_b_a" U3 ON (U2."id" = U3."b_id") WHERE U3."a_id" = (U0."a_id"))) LIMIT
 21; args=()
 }}}
 As suggested in the error, the `U2` join table does not seem to be defined
 in the generated query.

-- 
Ticket URL: 
Django 
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/049.77d22d9d80c32bfae13747d10e4e2afe%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.