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 bug in User.all_roles query + use SA2.0 #16761

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented Sep 28, 2023

I think this query never worked as intended: it always raised an error (clauses like joinedload(User.roles.role) don't work). The error was caught and silenced, so it was never detected.

The proposed solution produces a simple and straightforward query:

SELECT role.id, role.create_time, role.update_time, role.name, role.description, role.type, role.deleted 
FROM role JOIN user_role_association ON role.id = user_role_association.role_id JOIN galaxy_user ON galaxy_user.id = user_role
WHERE user_role_association.user_id = :user_id_1 UNION SELECT role.id, role.create_time, role.update_time, role.name, role.des
FROM role JOIN group_role_association ON role.id = group_role_association.role_id JOIN user_group_association ON user_group_as
WHERE user_group_association.user_id = :user_id_2

We union the user roles with the group roles for groups to which the user belongs - no need to apply multiple joinedload options to the User.

Ref: #12541

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.

@jdavcs jdavcs added kind/bug area/database Galaxy's database or data access layer labels Sep 28, 2023
@jdavcs jdavcs added this to the 23.2 milestone Sep 28, 2023
@jdavcs jdavcs requested a review from jmchilton September 28, 2023 20:31
@jdavcs jdavcs force-pushed the dev_fix_all_roles_query branch from e11608b to d559eb3 Compare September 28, 2023 21:32
@jdavcs
Copy link
Member Author

jdavcs commented Sep 29, 2023

Some failures seem relevant.

@jdavcs jdavcs marked this pull request as draft September 29, 2023 13:06
@jdavcs jdavcs mentioned this pull request Oct 2, 2023
18 tasks
)
roles = select(Role).from_statement(user_roles.union(user_group_roles))
return object_session(self).scalars(roles)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the join implicitly load the models now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not implicitly. It's the from_statement method: "...to use this SELECT statement as a source of complete [Foo] entities instead, we can link these columns to a regular ORM-enabled Select construct using the Select.from_statement() method" (ref)

@mvdbeek mvdbeek modified the milestones: 23.2, 24.0 Dec 19, 2023
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/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants