Skip to content
Snippets Groups Projects
Select Git revision
  • chat_identifier_parsers_claude_3_7-feature-flag
  • ci-cd-a11y-label-fixes
  • julianthome-master-patch-20405
  • sk/509374-add-rule-id
  • ag/519929-feature-flag-remove-block_seat_overages
  • rvzon-additional_note
  • andrey-validate-pipeline-common
  • 510851-policies-integration-tests-skip-ci
  • jc/local-board-experiment
  • adjust-feature-settings-mutation
  • 519123-convert-ff-require-email-verification-to-app-setting
  • move_save_git_content_outside_txn
  • 515973-dast-authentication-docs-improvements
  • master default protected
  • 514639-admin-custom-roles-saas
  • 507722-vsd-be-projects-by-dora-table-improve-the-accuracy-of-the-projects-representation
  • 442091-update-docs
  • charlieeekroon/remove-tool-documentation-in-vulnerability-management
  • overdue-finalize-background-migration--backfill-security-orchestration-policy-rule-schedules-namespace-id
  • ysiev-vulnerability-namespace-statistics-update-service
  • v17.7.6-ee protected
  • v17.8.4-ee protected
  • v17.9.1-ee protected
  • v17.8.3-ee protected
  • v17.7.5-ee protected
  • v17.9.0-ee protected
  • v17.9.0-rc42-ee protected
  • v17.6.5-ee protected
  • v17.7.4-ee protected
  • v17.8.2-ee protected
  • v17.6.4-ee protected
  • v17.7.3-ee protected
  • v17.8.1-ee protected
  • v17.8.0-ee protected
  • v17.7.2-ee protected
  • v17.8.0-rc42-ee protected
  • v17.5.5-ee protected
  • v17.6.3-ee protected
  • v17.7.1-ee protected
  • v17.7.0-ee protected
40 results

merge_requests_finder.rb

  • Stan Hu's avatar
    c5386724
    Fix 500 error sorting merge requests with approvers by milestone · c5386724
    Stan Hu authored
    When adding a `Approved By` or `Approver` filter and sorting by
    milestone, a 500 error will occur because of a SQL error:
    
    ```
    PG::GroupingError: ERROR:  column "milestones.due_date" must appear in
    the GROUP BY clause or be used in an aggregate function
    ```
    
    This happens because the approval query uses a `GROUP BY` query to
    find merge requests that match all approvers. However, this `GROUP BY`
    query breaks the SQL query since it's expected that
    `milestones.due_date` and `milestones.id` are present in that clause.
    
    We can solve this problem in a few ways:
    
    1. Add the required grouping columns to this query (this commit).
    2. Use a CTE to isolate the query for approvers.
    3. Rewrite the approvers query to avoid the GROUP BY altogether.
    
    The second way appears to work, but there's a risk of running into
    errors due to nested queries. Plus, it does not appear the CTE
    improves performance.
    
    The third way may also be possible, but it would possibly require some
    schema changes or other refactoring.
    
    For now, we can solve this problem by manually adding the required
    grouping columns when approvers are specified.
    
    Relates to #223062
    
    Changelog: fixed
    Verified
    c5386724
    History
    Fix 500 error sorting merge requests with approvers by milestone
    Stan Hu authored
    When adding a `Approved By` or `Approver` filter and sorting by
    milestone, a 500 error will occur because of a SQL error:
    
    ```
    PG::GroupingError: ERROR:  column "milestones.due_date" must appear in
    the GROUP BY clause or be used in an aggregate function
    ```
    
    This happens because the approval query uses a `GROUP BY` query to
    find merge requests that match all approvers. However, this `GROUP BY`
    query breaks the SQL query since it's expected that
    `milestones.due_date` and `milestones.id` are present in that clause.
    
    We can solve this problem in a few ways:
    
    1. Add the required grouping columns to this query (this commit).
    2. Use a CTE to isolate the query for approvers.
    3. Rewrite the approvers query to avoid the GROUP BY altogether.
    
    The second way appears to work, but there's a risk of running into
    errors due to nested queries. Plus, it does not appear the CTE
    improves performance.
    
    The third way may also be possible, but it would possibly require some
    schema changes or other refactoring.
    
    For now, we can solve this problem by manually adding the required
    grouping columns when approvers are specified.
    
    Relates to #223062
    
    Changelog: fixed
Code owners
Assign users and groups as approvers for specific file changes. Learn more.