#34229: "no such column" when combining FilteredRelation and multi-table
inheritance models
-------------------------------------+-------------------------------------
     Reporter:  Javier Ayres         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  filteredrelation     |             Triage Stage:  Accepted
  such column                        |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  closed => new
 * resolution:  duplicate =>
 * stage:  Unreviewed => Accepted


Comment:

 This case is more complicated so we decided to fix it separately, see a
 regression test:
 {{{#!diff
 diff --git a/tests/filtered_relation/models.py
 b/tests/filtered_relation/models.py
 index d34a86305f..dcd0197447 100644
 --- a/tests/filtered_relation/models.py
 +++ b/tests/filtered_relation/models.py
 @@ -44,6 +44,14 @@ class Borrower(models.Model):
      name = models.CharField(max_length=50, unique=True)


 +class Location(models.Model):
 +    small = models.BooleanField(default=False)
 +
 +
 +class Library(Location):
 +    editors = models.ManyToManyField(Editor, related_name="libraries")
 +
 +
  class Reservation(models.Model):
      NEW = "new"
      STOPPED = "stopped"
 diff --git a/tests/filtered_relation/tests.py
 b/tests/filtered_relation/tests.py
 index ce75cb01f5..9d38593065 100644
 --- a/tests/filtered_relation/tests.py
 +++ b/tests/filtered_relation/tests.py
 @@ -24,6 +24,7 @@ from .models import (
      Currency,
      Editor,
      ExchangeRate,
 +    Library,
      RentalSession,
      Reservation,
      Seller,
 @@ -825,6 +826,22 @@ class FilteredRelationAggregationTests(TestCase):
              [self.book1],
          )

 +    def test_condition_spans_mti(self):
 +        library = Library.objects.create(small=True)
 +        library.editors.add(self.editor_a)
 +        self.assertSequenceEqual(
 +            Editor.objects.annotate(
 +                small_libraries=FilteredRelation(
 +                    "libraries", condition=Q(libraries__small=True)
 +                ),
 +            )
 +            .filter(
 +                small_libraries__isnull=False,
 +            )
 +            .order_by("id"),
 +            [self.editor_a],
 +        )
 +

  class FilteredRelationAnalyticalAggregationTests(TestCase):
      @classmethod
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34229#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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070187b1f98278-be9f58fb-a6c2-4dc5-bf1c-e12407962cd8-000000%40eu-central-1.amazonses.com.

Reply via email to