Duplicate count queries on list endpoints with Python 3.8
At least 3 failing tests in dev with a Py3.8 virtualenv, on all three element list endpoints with with_has_children
:
1. SELECT (1) AS "a" FROM "documents_element" WHERE ("documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public") AND "documents_element"."id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) LIMIT 1
2. SELECT COUNT(*) AS "__count" FROM "documents_element" WHERE ("documents_element"."id" IN (SELECT unnest(U0."path") AS "parent_id" FROM "documents_elementpath" U0 WHERE U0."element_id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) AND "documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public"))
3. SELECT COUNT(*) FROM (SELECT "documents_element"."id" AS Col1 FROM "documents_element" INNER JOIN "documents_elementtype" ON ("documents_element"."type_id" = "documents_elementtype"."id") WHERE ("documents_element"."id" IN (SELECT unnest(U0."path") AS "parent_id" FROM "documents_elementpath" U0 WHERE U0."element_id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) AND "documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public")) ORDER BY "documents_element"."corpus_id" ASC, "documents_elementtype"."slug" ASC, "documents_element"."name" ASC, "documents_element"."id" ASC LIMIT 2) subquery
+4. SELECT COUNT(*) FROM (SELECT "documents_element"."id" AS Col1 FROM "documents_element" INNER JOIN "documents_elementtype" ON ("documents_element"."type_id" = "documents_elementtype"."id") WHERE ("documents_element"."id" IN (SELECT unnest(U0."path") AS "parent_id" FROM "documents_elementpath" U0 WHERE U0."element_id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) AND "documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public")) ORDER BY "documents_element"."corpus_id" ASC, "documents_elementtype"."slug" ASC, "documents_element"."name" ASC, "documents_element"."id" ASC LIMIT 2) subquery
+5. SELECT COUNT(*) FROM (SELECT "documents_element"."id" AS Col1 FROM "documents_element" INNER JOIN "documents_elementtype" ON ("documents_element"."type_id" = "documents_elementtype"."id") WHERE ("documents_element"."id" IN (SELECT unnest(U0."path") AS "parent_id" FROM "documents_elementpath" U0 WHERE U0."element_id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) AND "documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public")) ORDER BY "documents_element"."corpus_id" ASC, "documents_elementtype"."slug" ASC, "documents_element"."name" ASC, "documents_element"."id" ASC LIMIT 2) subquery
6. SELECT "documents_element"."id", "documents_element"."created", "documents_element"."updated", "documents_element"."corpus_id", "documents_element"."type_id", "documents_element"."name", "documents_element"."zone_id", "documents_element"."source_id", "documents_element"."worker_version_id", "documents_corpus"."created", "documents_corpus"."updated", "documents_corpus"."id", "documents_corpus"."name", "documents_corpus"."description", "documents_corpus"."repository_id", "documents_corpus"."public", "documents_elementtype"."id", "documents_elementtype"."corpus_id", "documents_elementtype"."slug", "documents_elementtype"."display_name", "documents_elementtype"."folder", "images_zone"."id", "images_zone"."created", "images_zone"."updated", "images_zone"."image_id", "images_zone"."polygon"::bytea FROM "documents_element" INNER JOIN "documents_corpus" ON ("documents_element"."corpus_id" = "documents_corpus"."id") INNER JOIN "documents_elementtype" ON ("documents_element"."type_id" = "documents_elementtype"."id") LEFT OUTER JOIN "images_zone" ON ("documents_element"."zone_id" = "images_zone"."id") WHERE ("documents_element"."id" IN (SELECT unnest(U0."path") AS "parent_id" FROM "documents_elementpath" U0 WHERE U0."element_id" = '9c80ae84-94a3-4ddd-97d8-a80fd73af9b2'::uuid) AND "documents_element"."corpus_id" IN (SELECT U0."id" FROM "documents_corpus" U0 WHERE U0."public")) ORDER BY "documents_element"."corpus_id" ASC, "documents_elementtype"."slug" ASC, "documents_element"."name" ASC, "documents_element"."id" ASC LIMIT 2
7. SELECT DISTINCT ON (e.id) e.id, p.id is not null as has_children FROM (VALUES ('3b9c805e-d190-4bc7-a8b0-2fdae4b6ab9f'::uuid),('9afec968-86bd-4c75-93e9-bf12a463e9df'::uuid)) e (id) LEFT JOIN documents_elementpath p ON (ARRAY[e.id] && p.path)