[Django] #31094: subquery uses ungrouped column "table.column" from outer query

60 views
Skip to first unread message

Django

unread,
Dec 16, 2019, 5:01:37 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes | Owner: nobody
Hoppe |
Type: Bug | Status: new
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Why upgrading to Django 3.0 I get the following issue:
{{{
subquery uses ungrouped column "t4.position" from outer query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
}}}


Full stack trace
{{{
Environment:


Request Method: GET
Request URL: http://localhost:8000/api/offer-map/

Django Version: 3.0
Python Version: 3.8.0
Installed Applications:
['django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'...',
'....',
'....',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.postgres',
'django.contrib.gis',
'django.forms',
'django_dramatiq',
'mailauth',
'mailauth.contrib.admin',
's3file',
'stdimage',
'adminsortable2',
'rest_framework',
'rest_framework_gis',
'django_filters',
'phonenumber_field',
'...']
Installed Middleware:
['log_request_id.middleware.RequestIDMiddleware',
'voiio.logging.middleware.UserAgentLogMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
's3file.middleware.S3FileMiddleware',
'accounts.middleware.CompanyMiddleware']

Traceback (most recent call last):
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)

The above exception (subquery uses ungrouped column "t4.position" from
outer query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
^
) was the direct cause of the following exception:
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/views.py", line 476, in
raise_uncaught_exception
raise exc
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/johannes/GitHub/voiio/voiio-platform/camps/viewsets.py",
line 344, in list
page = self.paginate_queryset(queryset)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/generics.py", line 171, in paginate_queryset
return self.paginator.paginate_queryset(queryset, self.request,
view=self)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/rest_framework/pagination.py", line 627, in
paginate_queryset
results = list(queryset[offset:offset + self.page_size + 1])
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/models/query.py", line 258, in __len__
self._fetch_all()
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch,
chunk_size=self.chunk_size)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/models/sql/compiler.py", line 1137, in
execute_sql
cursor.execute(sql, params)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False,
executor=self._execute)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 77, in
_execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/johannes/GitHub/voiio/voiio-platform/venv/lib/python3.8
/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /api/offer-map/
Exception Value: subquery uses ungrouped column "t4.position" from outer
query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
^
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 16, 2019, 5:03:41 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(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 Johannes Hoppe:

Old description:

> Full stack trace
> {{{
> Environment:
>

New description:

Why upgrading to Django 3.0 I get the following issue:
{{{
subquery uses ungrouped column "t4.position" from outer query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
}}}

Stack:
Python 3.8
PostgeSQL 11
macOS / Ubuntu latest

Full stack trace
{{{
Environment:

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:1>

Django

unread,
Dec 16, 2019, 5:10:58 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: needsinfo
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 felixxm):

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


Comment:

Can you provide a queryset? We'll not be able to reproduce this issue
without it. Can you also confirm that it works with Django 2.2?

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:2>

Django

unread,
Dec 16, 2019, 5:21:55 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(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 Johannes Hoppe):

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


Old description:

> Why upgrading to Django 3.0 I get the following issue:
> {{{
> subquery uses ungrouped column "t4.position" from outer query
> LINE 1: ..."."activity_type" AND ST_Contains(U2."locations",
> T4."positi...
> }}}
>

> Stack:
> Python 3.8
> PostgeSQL 11
> macOS / Ubuntu latest
>

> Full stack trace
> {{{
> Environment:
>

New description:

Why upgrading to Django 3.0 I get the following issue:
{{{
subquery uses ungrouped column "t4.position" from outer query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
}}}

It works fine in Django 2.2.8.

Stack:
Python 3.8
PostgeSQL 11
macOS / Ubuntu latest

Full query in 3.0 (pretty)
{{{
SELECT DISTINCT "camps_offer"."id", "camps_offer"."title",
"camps_offer"."slug", "camps_offer"."is_active", "camps_offer"."modified",
"camps_offer"."created", "camps_offer"."provider_id",
"camps_offer"."activity_type", "camps_offer"."description",
"camps_offer"."highlights", "camps_offer"."important_information",
"camps_offer"."min_age", "camps_offer"."max_age", "camps_offer"."food",
"camps_offer"."video", "camps_offer"."accommodation",
"camps_offer"."accommodation_type", "camps_offer"."room_type",
"camps_offer"."room_size_min", "camps_offer"."room_size_max",
"camps_offer"."external_url", "camps_offer"."application_form",
"camps_offer"."caseload", "camps_offer"."field_trips",
MIN(T4."retail_price") AS "min_retail_price", (SELECT U0."id" FROM
"camps_servicepackage" U0 INNER JOIN "camps_region" U2 ON (U0."region_id"
= U2."id") WHERE (U0."company_id" = 1 AND U0."option" =
"camps_offer"."activity_type" AND ST_Contains(U2."locations",
T4."position")) LIMIT 1) AS "in_package", "camps_provider"."id",
"camps_provider"."title", "camps_provider"."slug",
"camps_provider"."is_active", "camps_provider"."modified",
"camps_provider"."created", "camps_provider"."logo",
"camps_provider"."description", "camps_provider"."video",
"camps_provider"."external_url", "camps_provider"."terms",
"camps_provider"."cancellation_policy", "camps_provider"."privacy_policy",
"camps_provider"."application_form" FROM "camps_offer" LEFT OUTER JOIN
"camps_bookingoption" ON ("camps_offer"."id" =
"camps_bookingoption"."offer_id") INNER JOIN "camps_provider" ON
("camps_offer"."provider_id" = "camps_provider"."id") INNER JOIN
"camps_bookingoption" T4 ON ("camps_offer"."id" = T4."offer_id") WHERE
("camps_offer"."is_active" = True AND "camps_provider"."is_active" = True
AND T4."end" >= STATEMENT_TIMESTAMP() AND T4."is_active" = True AND
(SELECT U0."id" FROM "camps_servicepackage" U0 INNER JOIN "camps_region"
U2 ON (U0."region_id" = U2."id") WHERE (U0."company_id" = 1 AND
U0."option" = "camps_offer"."activity_type" AND
ST_Contains(U2."locations", T4."position")) LIMIT 1) IS NOT NULL) GROUP BY
"camps_offer"."id", "camps_provider"."id" ORDER BY "camps_offer"."created"
ASC
}}}

Full query in 2.2 (pretty)
{{{
SELECT DISTINCT "camps_offer"."id",
"camps_offer"."title",
"camps_offer"."slug",
"camps_offer"."is_active",
"camps_offer"."modified",
"camps_offer"."created",
"camps_offer"."provider_id",
"camps_offer"."activity_type",
"camps_offer"."description",
"camps_offer"."highlights",
"camps_offer"."important_information",
"camps_offer"."min_age",
"camps_offer"."max_age",
"camps_offer"."food",
"camps_offer"."video",
"camps_offer"."accommodation",
"camps_offer"."accommodation_type",
"camps_offer"."room_type",
"camps_offer"."room_size_min",
"camps_offer"."room_size_max",
"camps_offer"."external_url",
"camps_offer"."application_form",
"camps_offer"."caseload",
"camps_offer"."field_trips",
MIN(T4."retail_price") AS "min_retail_price",
(SELECT U0."id"
FROM "camps_servicepackage" U0
INNER JOIN "camps_region" U2 ON (U0."region_id"
= U2."id")
WHERE (U0."company_id" = 1 AND U0."option" =
("camps_offer"."activity_type") AND
ST_Contains(U2."locations", (T4."position")))
LIMIT 1) AS "in_package",
"camps_provider"."id",
"camps_provider"."title",
"camps_provider"."slug",
"camps_provider"."is_active",
"camps_provider"."modified",
"camps_provider"."created",
"camps_provider"."logo",
"camps_provider"."description",
"camps_provider"."video",
"camps_provider"."external_url",
"camps_provider"."terms",
"camps_provider"."cancellation_policy",
"camps_provider"."privacy_policy",
"camps_provider"."application_form"
FROM "camps_offer"
LEFT OUTER JOIN "camps_bookingoption" ON ("camps_offer"."id" =
"camps_bookingoption"."offer_id")
INNER JOIN "camps_provider" ON ("camps_offer"."provider_id" =
"camps_provider"."id")
INNER JOIN "camps_bookingoption" T4 ON ("camps_offer"."id" =
T4."offer_id")
WHERE ("camps_offer"."is_active" = True AND "camps_provider"."is_active" =
True AND
T4."end" >= (STATEMENT_TIMESTAMP()) AND T4."is_active" = True AND
(SELECT U0."id"
FROM "camps_servicepackage" U0
INNER JOIN "camps_region" U2 ON (U0."region_id" = U2."id")
WHERE (U0."company_id" = 1 AND
U0."option" = ("camps_offer"."activity_type") AND
ST_Contains(U2."locations", (T4."position")))
LIMIT 1) IS NOT NULL)
GROUP BY "camps_offer"."id",
(SELECT U0."id"
FROM "camps_servicepackage" U0
INNER JOIN "camps_region" U2 ON (U0."region_id" =
U2."id")
WHERE (U0."company_id" = 1 AND U0."option" =
("camps_offer"."activity_type") AND
ST_Contains(U2."locations", (T4."position")))
LIMIT 1), "camps_provider"."id"
ORDER BY "camps_offer"."created" ASC
}}}

Full stack trace
{{{
Environment:

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:3>

Django

unread,
Dec 16, 2019, 5:22:36 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(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 Johannes Hoppe:

Old description:

> Why upgrading to Django 3.0 I get the following issue:


> {{{
> subquery uses ungrouped column "t4.position" from outer query
> LINE 1: ..."."activity_type" AND ST_Contains(U2."locations",
> T4."positi...
> }}}
>

> It works fine in Django 2.2.8.
>
> Stack:
> Python 3.8
> PostgeSQL 11
> macOS / Ubuntu latest
>
> Full query in 3.0 (pretty)
> {{{
> SELECT DISTINCT "camps_offer"."id", "camps_offer"."title",
> "camps_offer"."slug", "camps_offer"."is_active",
> "camps_offer"."modified", "camps_offer"."created",
> "camps_offer"."provider_id", "camps_offer"."activity_type",
> "camps_offer"."description", "camps_offer"."highlights",
> "camps_offer"."important_information", "camps_offer"."min_age",
> "camps_offer"."max_age", "camps_offer"."food", "camps_offer"."video",
> "camps_offer"."accommodation", "camps_offer"."accommodation_type",
> "camps_offer"."room_type", "camps_offer"."room_size_min",
> "camps_offer"."room_size_max", "camps_offer"."external_url",
> "camps_offer"."application_form", "camps_offer"."caseload",
> "camps_offer"."field_trips", MIN(T4."retail_price") AS
> "min_retail_price", (SELECT U0."id" FROM "camps_servicepackage" U0 INNER
> JOIN "camps_region" U2 ON (U0."region_id" = U2."id") WHERE

> (U0."company_id" = 1 AND U0."option" = "camps_offer"."activity_type" AND
> ST_Contains(U2."locations", T4."position")) LIMIT 1) AS "in_package",


> "camps_provider"."id", "camps_provider"."title", "camps_provider"."slug",
> "camps_provider"."is_active", "camps_provider"."modified",
> "camps_provider"."created", "camps_provider"."logo",
> "camps_provider"."description", "camps_provider"."video",
> "camps_provider"."external_url", "camps_provider"."terms",
> "camps_provider"."cancellation_policy",
> "camps_provider"."privacy_policy", "camps_provider"."application_form"
> FROM "camps_offer" LEFT OUTER JOIN "camps_bookingoption" ON
> ("camps_offer"."id" = "camps_bookingoption"."offer_id") INNER JOIN
> "camps_provider" ON ("camps_offer"."provider_id" = "camps_provider"."id")
> INNER JOIN "camps_bookingoption" T4 ON ("camps_offer"."id" =
> T4."offer_id") WHERE ("camps_offer"."is_active" = True AND
> "camps_provider"."is_active" = True AND T4."end" >= STATEMENT_TIMESTAMP()
> AND T4."is_active" = True AND (SELECT U0."id" FROM "camps_servicepackage"
> U0 INNER JOIN "camps_region" U2 ON (U0."region_id" = U2."id") WHERE

> (U0."company_id" = 1 AND U0."option" = "camps_offer"."activity_type" AND

> Full stack trace
> {{{
> Environment:
>

New description:

Why upgrading to Django 3.0 I get the following issue:
{{{
subquery uses ungrouped column "t4.position" from outer query
LINE 1: ..."."activity_type" AND ST_Contains(U2."locations", T4."positi...
}}}

It works fine in Django 2.2.8.

"camps_offer"."activity_type" AND
ST_Contains(U2."locations", T4."position"))

Full stack trace
{{{
Environment:

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:4>

Django

unread,
Dec 16, 2019, 5:25:37 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(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
-------------------------------------+-------------------------------------

Comment (by Johannes Hoppe):

A quick diff of the query in both versions, shows a diff in the grouping
section:

{{{


< GROUP BY "camps_offer"."id", "camps_provider"."id"

---


> GROUP BY "camps_offer"."id",
> (SELECT U0."id"
> FROM "camps_servicepackage" U0
> INNER JOIN "camps_region" U2 ON (U0."region_id" =
U2."id")
> WHERE (U0."company_id" = 1 AND U0."option" =
("camps_offer"."activity_type") AND
> ST_Contains(U2."locations", (T4."position")))
> LIMIT 1), "camps_provider"."id"
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:5>

Django

unread,
Dec 16, 2019, 7:32:55 AM12/16/19
to django-...@googlegroups.com
#31094: subquery uses ungrouped column "table.column" from outer query
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(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
-------------------------------------+-------------------------------------

Comment (by felixxm):

I agree that there is probably some regression in such queries, but it's
really hard to restore the original queryset from a raw SQL. Can you
provide a queryset? If not I will try to reproduce this issue in our test
suite.

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:6>

Django

unread,
Dec 16, 2019, 10:01:03 AM12/16/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.

-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* cc: Simon Charette (added)
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker


Comment:

I was able to reproduce this issue with attached test, thanks for the
report.

Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.

Reproduced at 972d93a95ec8b37fab84400417070b7439414967.

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:7>

Django

unread,
Dec 16, 2019, 10:01:43 AM12/16/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* Attachment "test-31094.diff" added.

Regression test.

Django

unread,
Dec 16, 2019, 10:38:23 AM12/16/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: assigned

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* owner: nobody => Simon Charette
* status: new => assigned


Comment:

I think the correct solution here will be to make
`Subquery.get_group_by_cols` return all its `OuterRef` expressions when
`alias is None`; that is the ones contained in its annotations and where
clause.

That would result in an additional `GROUP BY T4."position"` in the outer
query as PostgreSQL expects.

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:8>

Django

unread,
Dec 17, 2019, 2:01:46 AM12/17/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Johannes Hoppe):

Hey Simon, I have only limited experience with this part of the ORM, so I
don't know if I can be of much help. However, I am happy to review
anything you throw at me. Best -Joe

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:9>

Django

unread,
Dec 17, 2019, 2:07:52 AM12/17/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


Comment:

Hey Johannes, I'd gladly provide answers to your questions on
https://github.com/django/django/pull/12227 if you have any.

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:10>

Django

unread,
Dec 19, 2019, 3:27:12 AM12/19/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:11>

Django

unread,
Dec 19, 2019, 5:10:55 AM12/19/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5a4d7285bd10bd40d9f7e574a7c421eb21094858" 5a4d7285]:
{{{
#!CommitTicketReference repository=""
revision="5a4d7285bd10bd40d9f7e574a7c421eb21094858"
Fixed #31094 -- Included columns referenced by subqueries in GROUP BY on
aggregations.

Thanks Johannes Hoppe for the report.

Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.

Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:13>

Django

unread,
Dec 19, 2019, 5:10:55 AM12/19/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: assigned

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"a0f34d8fef2942e17c40e7009b355b661d30e138" a0f34d8f]:
{{{
#!CommitTicketReference repository=""
revision="a0f34d8fef2942e17c40e7009b355b661d30e138"
Refs #31094 -- Added test for not using aliases in GROUP BY clauses.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:12>

Django

unread,
Dec 19, 2019, 5:11:32 AM12/19/19
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"fd9050589f5f99d61bf1c68917a9157c1e8c3752" fd905058]:
{{{
#!CommitTicketReference repository=""
revision="fd9050589f5f99d61bf1c68917a9157c1e8c3752"
[3.0.x] Fixed #31094 -- Included columns referenced by subqueries in GROUP
BY on aggregations.

Thanks Johannes Hoppe for the report.

Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.

Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>

Backport of 5a4d7285bd10bd40d9f7e574a7c421eb21094858 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:14>

Django

unread,
Jan 9, 2020, 6:47:24 AM1/9/20
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Hoppe | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Johannes Hoppe):

Dang, this isn't over yet, seealso #31150

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:15>

Django

unread,
Feb 24, 2021, 4:11:47 AM2/24/21
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: Simon

| Charette
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"277eea8fcced7f04f3800617f189beb349a3212e" 277eea8f]:
{{{
#!CommitTicketReference repository=""
revision="277eea8fcced7f04f3800617f189beb349a3212e"
Fixed #32478 -- Included nested columns referenced by subqueries in GROUP
BY on aggregations.

Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.

Refs #31094, #31150.

Thanks Igor Pejic for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:16>

Django

unread,
Feb 24, 2021, 4:12:08 AM2/24/21
to django-...@googlegroups.com
#31094: Subquery uses ungrouped column "table.column" from outer query.
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"7a6ca01f4eb990772080e2978f19d83484184b04" 7a6ca01]:
{{{
#!CommitTicketReference repository=""
revision="7a6ca01f4eb990772080e2978f19d83484184b04"
[3.2.x] Fixed #32478 -- Included nested columns referenced by subqueries


in GROUP BY on aggregations.

Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80.

Refs #31094, #31150.

Thanks Igor Pejic for the report.

Backport of 277eea8fcced7f04f3800617f189beb349a3212e from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31094#comment:17>

Reply all
Reply to author
Forward
0 new messages