Custom Query (27093 matches)


Show under each result:

Results (22 - 24 of 27093)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Ticket Resolution Summary Owner Reporter
#29197 invalid TemplateDoesNotExist: postgres/widgets/split_array.html nobody linluc

In my model I use:

user_choices = ArrayField(models.BooleanField(), default=[], size=5)

then on the form, in the widgets section (first import: from django.contrib.postgres.forms import SplitArrayWidget):

'user_choices' : SplitArrayWidget(forms.CheckboxInput(),5)

The above combination throws:

Django Version: 2.0.1 Exception Type: TemplateDoesNotExist Exception Value: postgres/widgets/split_array.html

The issue seems easy to fix, by either fixing the path in "/lib/python3.4/site-packages/django/contrib/postgres/forms/", which currently reads:

template_name = 'postgres/widgets/split_array.html'

or by moving the postgres template directory, which is located one level above.

#29196 invalid Chaining multiple filters duplicates `INNER JOIN` for the final query nobody Ivaylo Donchev

Let's say we have the following model structure:

    from django.db import models

    class Country(models.Model):
        name = models.CharField(max_length=255)

    class Group(models.Model):
        title = models.CharField(max_length=255)

    class Actor(models.Model):
        name = models.CharField(max_length=255)
        def __str__(self):
            return f'{} - (id={})'

    class Follower(models.Model):
        full_name = models.CharField(max_length=255)
        actor = models.ForeignKey(Actor,
        country = models.ForeignKey(Country,
        group = models.ForeignKey(Group,

And I want to get all the actors who have a follower who has a relation BOTH to a country with 'name="Bulgaria"' AND a group with 'title="Programmers"'.

In the database I have:


  • id=1, name="Gerard Butler"


  • id=1, name="Bulgaria"
  • id=1, name="Germany"


  • id=1, full_name="Ivo", country="Bulgaria", actor=<actor with id=1>
  • id=2, full_name="Martin", country="Germany", actor=<actor with id=1>


  • id=1, title="Sportists"
  • id=2, title="Programmers"

So when I execute the following query:

Actor.objects.filter(followers__country__name='Bulgaria', followers__group__title='Sportists')

I'm getting the right result: <QuerySet [<Actor: Gerard Butler - (id=1)>]>

But If I chain the two filters as follows:


I got a queryset of the duplicated object: <QuerySet [<Actor: Gerard Butler - (id=1)>, <Actor: Gerard Butler - (id=1)>]>

Is this an expected behaviour or a bug?

PS: If it's going to be helpful:

The query, produced from the first queryset(Actor.objects.filter(followers__country__name='Bulgaria', followers__group__title='Sportists')) is:

SELECT "sample_actor"."id", "sample_actor"."name"
    FROM "sample_actor"
    INNER JOIN "sample_follower"
        ON ("sample_actor"."id" = "sample_follower"."actor_id")
    INNER JOIN "sample_country"
        ON ("sample_follower"."country_id" = "sample_country"."id")
    INNER JOIN "sample_group"
        ON ("sample_follower"."group_id" = "sample_group"."id")
    WHERE ("sample_country"."name" = Bulgaria AND "sample_group"."title" = Sportists)

And the query from the second queryset(Actor.objects.filter(followers__country__name='Bulgaria').filter(followers__group__title='Sportists')) is:

SELECT "sample_actor"."id", "sample_actor"."name"
    FROM "sample_actor"
    INNER JOIN "sample_follower"
        ON ("sample_actor"."id" = "sample_follower"."actor_id")
    INNER JOIN "sample_country"
        ON ("sample_follower"."country_id" = "sample_country"."id")
    INNER JOIN "sample_follower" T4
        ON ("sample_actor"."id" = T4."actor_id")
    INNER JOIN "sample_group" ON (T4."group_id" = "sample_group"."id")
    WHERE ("sample_country"."name" = Bulgaria AND "sample_group"."title" = Sportists)

So there's a duplicated INNER JOIN when chaining the filters. I hope this will help!

Greetings ;)

#29195 fixed Postgres Regression, annotating Exists through a OuterRef query. Simon Charette Oli Warner

First proper report here, sorry if I mess it up. I've been using some fairly advance subqueries since they were released but on upgrading a mature-ish 1.11 site to 2.0 I notice that some of these broke. I've distilled this down to a very simple pair of models and a test. This passes on SQLite, fails on Postgres 10 and 9.6. Worked on both in Django 1.11.

All I'm trying to do here is find Booking instances that have any Payments linked to them.

from django.db import models

class Booking(models.Model):

class Payment(models.Model):
    booking = models.ForeignKey('Booking', models.CASCADE)
from django.test import TestCase
from django.db.models import Exists, OuterRef

from .models import Booking, Payment

class AnnotateTestCase(TestCase):
    def setUp(self):
        self.booking_one = Booking.objects.create()
        self.booking_two = Booking.objects.create()


    def test_annotation(self):
        # find bookings with payments
        payment_query = Payment.objects.order_by().filter(booking=OuterRef('pk')).values('booking')
        booking_query = Booking.objects.all().annotate(has_payments=Exists(payment_query)).filter(has_payments=True)

        self.assertEqual(booking_query.count(), 1)

I've also tested the master branch. Same problem. Here's the trace.

Traceback (most recent call last):
  File "/home/oli/Desktop/testsite/testsite/myapp/", line 19, in test_annotation
    self.assertEqual(booking_query.count(), 1)
  File "/home/oli/Desktop/testsite/django/django/db/models/", line 382, in count
    return self.query.get_count(using=self.db)
  File "/home/oli/Desktop/testsite/django/django/db/models/sql/", line 494, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "/home/oli/Desktop/testsite/django/django/db/models/sql/", line 479, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "/home/oli/Desktop/testsite/django/django/db/models/sql/", line 1053, in execute_sql
    cursor.execute(sql, params)
  File "/home/oli/Desktop/testsite/django/django/db/backends/", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/oli/Desktop/testsite/django/django/db/backends/", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/oli/Desktop/testsite/django/django/db/backends/", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/oli/Desktop/testsite/django/django/db/", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/oli/Desktop/testsite/django/django/db/backends/", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: operator does not exist: boolean = integer
LINE 1: ...0 WHERE U0."booking_id" = ("myapp_booking"."id")) = 1 GROUP ...
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Note: See TracQuery for help on using queries.
Back to Top