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

[23.1] Fix ancient bug: incorrect usage of func.coalesce in User model #17577

Merged
merged 1 commit into from Mar 4, 2024

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented Mar 1, 2024

SQLAlchemy BinaryExpression incorrectly assigned as value to user.disk_usage. Should be a numeric value.

This bug was introduced 9 years ago. I believe here's what happened: when this was introduced, there was one other use of func.coalesce related to disk size calculation (here); however, in that other case, the expression was part of a SELECT statement - so it was sent to the database, where it invoked the database's coalesce function, which did what it should do. However, in the new expression, it was not sent to the database. This was never caught because we never checked that value before flushing the session somewhere else, and upon flush, the session did send that value to the database, where that value was evaluated by the db and was stored correctly. However, if we were to access user.disk_usage after calling adjust_disk_usage() but before flushing or committing to the database, we'd get an error, because instead of a decimal, we'd get a SQLAlchemy BinaryExpression type:

(Pdb) u1.total_disk_usage
<sqlalchemy.sql.elements.BinaryExpression object at 0x7f8da9b5c8e0>
(Pdb) str(u1.total_disk_usage)
'coalesce(galaxy_user.disk_usage, :coalesce_1) + :coalesce_2'

This is currently tested in test_galaxy_mapping.py. It works because before accessing this attribute, the test calls session.expunge().

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 requested review from jmchilton and a team March 1, 2024 22:41
@github-actions github-actions bot added the area/database Galaxy's database or data access layer label Mar 1, 2024
@github-actions github-actions bot added this to the 24.1 milestone Mar 1, 2024
@jdavcs jdavcs added kind/bug area/database Galaxy's database or data access layer and removed area/database Galaxy's database or data access layer labels Mar 1, 2024
@jdavcs jdavcs modified the milestones: 24.1, 24.0 Mar 1, 2024
@jdavcs jdavcs changed the base branch from dev to release_23.0 March 1, 2024 22:55
@jdavcs jdavcs changed the title [23.0] Fix ancient bug: incorrect usage of func.coalesce in User model [23.1] Fix ancient bug: incorrect usage of func.coalesce in User model Mar 1, 2024
@jdavcs jdavcs changed the base branch from release_23.0 to release_23.1 March 1, 2024 22:55
@davelopez
Copy link
Contributor

Makes sense, thanks for the detailed explanation.

@jdavcs jdavcs removed this from the 24.0 milestone Mar 4, 2024
@jdavcs jdavcs merged commit fab4424 into galaxyproject:release_23.1 Mar 4, 2024
56 of 58 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/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants