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

Upgrade job manager's index_query method to SA2.0 #17020

Merged
merged 9 commits into from
Nov 14, 2023

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented Nov 13, 2023

SQLAlchemy 2.0 compatibility upgrades. Ref #12541. Extracted from #16852.

Two notable edits:

  1. Calling union() on a Select statement creates a CompoundSelect object; executing it will return tuples of column values, not models. This causes a problem because the method is expected to return models in all cases. To ensure the method always returns models (regardless of whether the union is called or not), I used aliased() to map the Job model to the CompoundSelect object.
  2. The combination of UNION and ORDER BY causes problems in SQLite. More details here: SQLAlchemy 2.0 upgrades (part 4) #16852 (comment). Solution: instead of using the Job class to access the column collection, use Job only if workflow jobs have not been added to the statement (and UNION has not been applied). Otherwise use the subquery produced by the union.

I've restructured the method - I think it's easier to follow its query-building logic this way. But if that's not the case, I'll drop the last commit.

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

Calling union() on a statement creates a CompoundSelect object;
executing it will return tuples of column values, not models. To ensure
the method always returns models (regardless of whether the union is
called or not), we use aliased() to map the Job model to the
CompoundSelect.
(I think factoring out these complex chunks of logic into local
functions makes it easier to follow the main query-building logic.)
@jdavcs jdavcs added kind/refactoring cleanup or refactoring of existing code, no functional changes area/database Galaxy's database or data access layer labels Nov 13, 2023
@jdavcs jdavcs added this to the 23.2 milestone Nov 13, 2023
@jdavcs jdavcs marked this pull request as ready for review November 13, 2023 22:50
@jdavcs jdavcs requested a review from a team November 13, 2023 22:50
@jdavcs jdavcs merged commit 4db3b94 into galaxyproject:dev Nov 14, 2023
45 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/database Galaxy's database or data access layer kind/refactoring cleanup or refactoring of existing code, no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants