With PostgreSQL this leads to the following SQL (I've reduced the SQL to
one field only -> "..."):
{{{
(SELECT "wagtailcore_pagelogentry"."id", ... FROM
"wagtailcore_pagelogentry" LIMIT 1) LIMIT 1;
}}}
which results in this error:
{{{
psycopg2.errors.SyntaxError: multiple LIMIT clauses not allowed
LINE 1: ..."."page_id" FROM "wagtailcore_pagelogentry" LIMIT 1) LIMIT 1
}}}
With django 4.1.2 the following valid SQL is generated:
{{{
(SELECT "wagtailcore_pagelogentry"."id", ... FROM
"wagtailcore_pagelogentry") LIMIT 1;
}}}
With sqlite no errors are thrown in the dev-version.
Note: In our actual queries, we use ordering (we remove ordering in the
inner queries with `order_by()` and apply an ordering to the resulting
union-queryset), but that does not change anything, since the limit seems
to be the issue, so I've removed ordering to minimize the SQL.
I've found a similar, fixed bug #32116, but in that case order_by had an
issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/34125>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: bcail (added)
Comment:
Using the following diff:
{{{
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 5163fc5cb1..31651df114 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -3199,6 +3199,11 @@ class UnionTests(unittest.TestCase):
)
self.check_union(ObjectB, Q1, Q2)
+ def test_union_empty_queryset(self):
+ q1 = ObjectA.objects.all().order_by()
+ q2 = q1.union(ObjectA.objects.none())
+ print(q2.order_by()[:1])
+
class DefaultValuesInsertTest(TestCase):
def test_no_extra_params(self):
}}}
git bisect says that 3d734c09ff0138441dfe0a59010435871d17950f is the first
bad commit.
--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:1>