"UNION query" error since django 1.11.13|2.0.5

Issue #106 resolved
Former user created an issue

Everything work well before django 2.0.5.
But since django 2.0.5 I have an error when I try to go to the inbox, outbox, archives or trash.

Request Method: GET
Request URL: http://site.mo/messages/inbox/
Django Version: 2.0.5
Exception Type: ProgrammingError
Exception Value: each UNION query must have the same number of columns

LINE 1: ...tman_message"."thread_id" IS NULL)) UNION (SELECT MAX("postm...
                                                             ^

Exception Location:     /home/me/site/env3/lib/python3.6/site-packages/django/db/backends/utils.py in _execute, line 85
Python Executable:  /home/me/site/env3/bin/python3
Python Version:     3.6.5
ignored_wrapper_args    

(False,
 {'connection': <django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f17113a4a90>,
  'cursor': <django.db.backends.utils.CursorDebugWrapper object at 0x7f170e150b00>})

params  

(1, False, 1, False)

self    

<django.db.backends.utils.CursorDebugWrapper object at 0x7f170e150b00>

sql     

('SELECT (PM.count) AS "count", "postman_message"."id", '
 '"postman_message"."subject", "postman_message"."body", '
 '"postman_message"."sender_id", "postman_message"."recipient_id", '
 '"postman_message"."email", "postman_message"."parent_id", '
 '"postman_message"."thread_id", "postman_message"."sent_at", '
 '"postman_message"."read_at", "postman_message"."replied_at", '
 '"postman_message"."sender_archived", "postman_message"."recipient_archived", '
 '"postman_message"."sender_deleted_at", '
 '"postman_message"."recipient_deleted_at", '
 '"postman_message"."moderation_status", "postman_message"."moderation_by_id", '
 '"postman_message"."moderation_date", "postman_message"."moderation_reason", '
 '"auth_user"."id", "auth_user"."password", "auth_user"."last_login", '
 '"auth_user"."is_superuser", "auth_user"."username", '
 '"auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", '
 '"auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" '
 'FROM "postman_message" INNER JOIN ((SELECT (0) AS "count", '
 '"postman_message"."id" FROM "postman_message" WHERE '
 '("postman_message"."sender_id" = %s AND "postman_message"."sender_archived" '
 '= %s AND "postman_message"."sender_deleted_at" IS NULL AND '
 '"postman_message"."thread_id" IS NULL)) UNION (SELECT '
 'MAX("postman_message"."id") AS "id" FROM "postman_message" WHERE '
 '("postman_message"."sender_id" = %s AND "postman_message"."sender_archived" '
 '= %s AND "postman_message"."sender_deleted_at" IS NULL AND '
 '"postman_message"."thread_id" IS NOT NULL) GROUP BY '
 '"postman_message"."thread_id")) PM ON ("postman_message"."id" = PM."id") '
 'LEFT OUTER JOIN "auth_user" ON ("postman_message"."recipient_id" = '
 '"auth_user"."id") ORDER BY "postman_message"."sent_at" DESC, '
 '"postman_message"."id" DESC')

Comments (4)

  1. Patrick Samson repo owner
    • changed status to open

    The QuerySet union() operator had a bug in 1.11.8+|2.0+.
    It was fixed in 1.11.12|2.0.4 (Dj ticket 29229).
    But reintroduced in 1.11.13|2.0.5 (Dj ticket 29286).
    We have to wait the fix for Dj ticket 29694.

    Meanwhile, as a workaround, you can tweak postman\query.py\line 90 as:

            if VERSION < (1, 11, 99) or (2, 0) <= VERSION < (2, 0, 99):
    
  2. Log in to comment