Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #979 #980

Merged
merged 2 commits into from
Mar 13, 2024
Merged

fix for #979 #980

merged 2 commits into from
Mar 13, 2024

Conversation

epugh
Copy link
Member

@epugh epugh commented Mar 13, 2024

Description

Motivation and Context

How Has This Been Tested?

Screenshots or GIFs (if appropriate):

Types of changes

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] Improvement (non-breaking change which improves existing functionality)
  • [] New feature (non-breaking change which adds new functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [] My code follows the code style of this project.
  • [] My change requires a change to the documentation.
  • [] I have updated the documentation accordingly.
  • [] I have read the CONTRIBUTING document.
  • [] I have added tests to cover my changes.
  • [] All new and existing tests passed.

@epugh
Copy link
Member Author

epugh commented Mar 13, 2024

@reid-rigo I'm going to merge this PR as a hotfix, however, I'd love your thoughts on if this fix is "the right" fix!

@epugh
Copy link
Member Author

epugh commented Mar 13, 2024

Argh.. lots of errors.... Now I remember why i disliked "distinct"...

Listing cases#test_does_not_return_archived_cases_by_default (36.11s)
Minitest::UnexpectedError:         RuntimeError: Neutered Exception ActionView::Template::Error: Mysql2::Error: Expression #1 of ORDER BY clause is not in SELECT list, references column 'quepid_test.case_metadata.last_viewed_at' which is not in SELECT list; this is incompatible with DISTINCT
            app/views/api/v1/cases/index.json.jbuilder:4
            app/views/api/v1/cases/index.json.jbuilder:3
            app/controllers/api/v1/cases_controller.rb:69:in `index'
            test/controllers/api/v1/cases_controller_test.rb:471:in `block (2 levels) in <class:CasesControllerTest>'

@epugh
Copy link
Member Author

epugh commented Mar 13, 2024

I hate that this generates two queries! But...

@epugh epugh merged commit 14e5c6c into main Mar 13, 2024
5 checks passed
@reid-rigo
Copy link
Contributor

Huh, thanks for fixing this. It looks like this is needed for that order:

diff --git a/app/controllers/api/v1/cases_controller.rb b/app/controllers/api/v1/cases_controller.rb
index a92be2d4..844b5548 100644
--- a/app/controllers/api/v1/cases_controller.rb
+++ b/app/controllers/api/v1/cases_controller.rb
@@ -62,6 +62,7 @@ module Api
                      current_user.cases_involved_with.not_archived.with_counts.preload(:tries, :teams,
                                                                                        :cases_teams)
                        .left_outer_joins(:metadata)
+                       .select('cases.*, case_metadata.last_viewed_at')
                        .order(Arel.sql('`case_metadata`.`last_viewed_at` DESC, `cases`.`updated_at` DESC'))
                    end
         end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants