Просмотр исходного кода

Fixes #4846 - Overview with condition 'subscribe -> is specific user' throws PG::CardinalityViolation when query hits more than one user.

Martin Gruner 1 год назад
Родитель
Сommit
e53a0c32a8
2 измененных файлов с 6 добавлено и 4 удалено
  1. 2 2
      app/models/ticket/selector/sql.rb
  2. 4 2
      spec/models/ticket_spec.rb

+ 2 - 2
app/models/ticket/selector/sql.rb

@@ -229,9 +229,9 @@ class Ticket::Selector::Sql < Ticket::Selector::Base
                  end
       else
         query << if block_condition[:operator] == 'is'
-                   "1 = (SELECT 1 FROM mentions mentions_sub WHERE mentions_sub.mentionable_type = 'Ticket' AND mentions_sub.mentionable_id = tickets.id AND mentions_sub.user_id IN (?))"
+                   "1 = (SELECT 1 FROM mentions mentions_sub WHERE mentions_sub.mentionable_type = 'Ticket' AND mentions_sub.mentionable_id = tickets.id AND mentions_sub.user_id IN (?) LIMIT 1)"
                  else
-                   "(SELECT 1 FROM mentions mentions_sub WHERE mentions_sub.mentionable_type = 'Ticket' AND mentions_sub.mentionable_id = tickets.id AND mentions_sub.user_id IN (?)) IS NULL"
+                   "(SELECT 1 FROM mentions mentions_sub WHERE mentions_sub.mentionable_type = 'Ticket' AND mentions_sub.mentionable_id = tickets.id AND mentions_sub.user_id IN (?) LIMIT 1) IS NULL"
                  end
         if block_condition[:pre_condition] == 'current_user.id'
           bind_params.push current_user_id

+ 4 - 2
spec/models/ticket_spec.rb

@@ -2231,11 +2231,13 @@ RSpec.describe Ticket, type: :model do
       end
 
       it 'pre condition is specific' do
+        create(:mention, mentionable: ticket_mentions, user: user_mentions_2)
+
         condition = {
           'ticket.mention_user_ids' => {
             pre_condition: 'specific',
             operator:      'is',
-            value:         user_mentions.id
+            value:         [user_mentions.id, user_mentions_2.id]
           },
         }
 
@@ -2248,7 +2250,7 @@ RSpec.describe Ticket, type: :model do
           'ticket.mention_user_ids' => {
             pre_condition: 'specific',
             operator:      'is not',
-            value:         user_mentions.id
+            value:         [user_mentions.id, user_mentions_2.id]
           },
         }