#1845 QueryProcessor: fix countOnly for group sql
Merged 2 years ago by tkopecek. Opened 2 years ago by julian8628.
julian8628/koji issue/1844  into  master

file modified
+6 -2
@@ -8673,7 +8673,9 @@ 

   %(limit_str)s

  """

          if self.opts.get('countOnly'):

-             if self.opts.get('offset') or self.opts.get('limit'):

+             if self.opts.get('offset') \

+                     or self.opts.get('limit') \

+                     or (self.enable_group and self.opts.get('group')):

                  # If we're counting with an offset and/or limit, we need

                  # to wrap the offset/limited query and then count the results,

                  # rather than trying to offset/limit the single row returned
@@ -8699,7 +8701,9 @@ 

  

          query = query % locals()

          if self.opts.get('countOnly') and \

-            (self.opts.get('offset') or self.opts.get('limit')):

+             (self.opts.get('offset') or

+              self.opts.get('limit') or

+              (self.enable_group and self.opts.get('group'))):

              query = 'SELECT count(*)\nFROM (' + query + ') numrows'

          if self.opts.get('rowlock'):

              query += '\n FOR UPDATE'

@@ -75,6 +75,7 @@ 

                     " ORDER BY something OFFSET 10 LIMIT 3"

          self.assertEqual(actual, expected)

  

+ 

      @mock.patch('kojihub.context')

      def test_simple_with_execution(self, context):

          cursor = mock.MagicMock()
@@ -95,6 +96,18 @@ 

          cursor.execute.assert_called_once_with('\nSELECT count(*)\n  FROM awesome\n\n\n \n \n\n \n', {})

          self.assertEqual(results, 'some count')

  

+         cursor.reset_mock()

+         args['opts']['group'] = 'id'

+         args['enable_group'] = True

+         proc = kojihub.QueryProcessor(**args)

+         results = proc.execute()

+         cursor.execute.assert_called_once_with(

+             'SELECT count(*)\nFROM (\nSELECT 1\n'

+             '  FROM awesome\n\n\n GROUP BY id\n \n\n \n) numrows', {})

+         self.assertEqual(results, 'some count')

+ 

+ 

+ 

      @mock.patch('kojihub.context')

      def test_simple_execution_with_iterate(self, context):

          cursor = mock.MagicMock()

Metadata Update from @julian8628:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

2 years ago

Commit f024e48 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago