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

[24.1] Allow to change only the description of a quota #18775

Conversation

bernt-matthias
Copy link
Contributor

A quota update via API requires name or quota to be set, but the manager requires a name to be set.

If one wants to change just the description of a quota the used select statement gets the quota itself and the elif branch hits resulting in an exception.

With the change one can change just the description, but one still needs to specify the name of the quota. We could hange this such that also in the manager the name of the quota needs to be specified.

I guess in the admin UI this has not been a problem because the name and description are prefilled with the old values.

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.

@bernt-matthias bernt-matthias changed the title [24.1] Allow to change description of a quota [24.1] Allow to change only the description of a quota Sep 4, 2024
@github-actions github-actions bot added this to the 24.1 milestone Sep 4, 2024
@bernt-matthias bernt-matthias requested a review from a team September 5, 2024 13:42
@mvdbeek mvdbeek requested review from a team and removed request for a team September 16, 2024 09:54
@jdavcs
Copy link
Member

jdavcs commented Sep 16, 2024

Since we can now update just the description, this message needs to be edited too. I'd keep it simple (e.g. "has been updated") and not worry about specifying what exactly was updated (name or description or both, etc.)

@jdavcs
Copy link
Member

jdavcs commented Sep 16, 2024

@bernt-matthias Sorry, I'm confused; can you, please, explain why "If one wants to change just the description of a quota the used select statement gets the quota itself and the elif branch hits resulting in an exception."? I'm looking at this:
elif params.name != quota.name and self.sa_session.scalars(stmt).first():.

@mvdbeek
Copy link
Member

mvdbeek commented Sep 16, 2024

Those messages are not the most insightful anyway, I would follow up on dev and remove them all. Either we got a 200 response and it's good or we got an exception.

@jdavcs
Copy link
Member

jdavcs commented Sep 16, 2024

Those messages are not the most insightful anyway, I would follow up on dev and remove them all. Either we got a 200 response and it's good or we got an exception.

Strongly agree. An update can mean a lot of things, including any combination of updated values, some derived from others, etc. Besides, even if we constructed a detailed message, I don't think it would be useful. And a generic "has been updated" message, if at all needed, can be constructed on the client.

@bernt-matthias
Copy link
Contributor Author

@bernt-matthias Sorry, I'm confused; can you, please, explain why "If one wants to change just the description of a quota the used select statement gets the quota itself and the elif branch hits resulting in an exception."? I'm looking at this: elif params.name != quota.name and self.sa_session.scalars(stmt).first():.

Lets say there is a quota with name "A" and description "", and I want to update the description to "Description of A". Then the function will get params.name = "A" and the new description. Then stmt = select(Quota).where(Quota.name == params.name) will return the quota which I try to update (actually it is the same as the argument quota). I.e. the old code will raise ActionInputError("A quota with that name already exists."). Which is kind of True but not what should actually be checked here:

Instead of checking: Is there a quota with name X it needs to check is there another quota with name X.

@jdavcs
Copy link
Member

jdavcs commented Sep 17, 2024

Lets say there is a quota with name "A" and description "", and I want to update the description to "Description of A". Then the function will get params.name = "A" and the new description. Then stmt = select(Quota).where(Quota.name == params.name) will return the quota which I try to update (actually it is the same as the argument quota). I.e. the old code will raise ActionInputError("A quota with that name already exists."). Which is kind of True but not what should actually be checked here:

Instead of checking: Is there a quota with name X it needs to check is there another quota with name X.

Thanks! But still, I'm looking at the old code: it'll raise an error only if both conditions are true:
params.name != quota.name and self.sa_session.scalars(stmt).first() - i.e., "I am changing the name of quota" AND "a quota with this new name exists". So, if I'm NOT changing quota.name, then the first expression will evaluate to False and the exception won't be raised, right? Am I misreading this logic?

That said, I think your version is better, because it's immediately clear from looking at the statement that it answers the question "is there a quota record with that name that is not the quota I am editing?" - which is very easy to read!

Also, with this statement, I think you don't need to check params.name != quota.name in the elif clause anymore.

@bernt-matthias
Copy link
Contributor Author

Thanks! But still, I'm looking at the old code: it'll raise an error only if both conditions are true: params.name != quota.name and self.sa_session.scalars(stmt).first() - i.e., "I am changing the name of quota" AND "a quota with this new name exists". So, if I'm NOT changing quota.name, then the first expression will evaluate to False and the exception won't be raised, right? Am I misreading this logic?

That is correct.

That said, I think your version is better, because it's immediately clear from looking at the statement that it answers the question "is there a quota record with that name that is not the quota I am editing?" - which is very easy to read!

:)

Also, with this statement, I think you don't need to check params.name != quota.name in the elif clause anymore.

I think we should not change this in a bug fix.

But I think you are right as long as we assume that we have unique names. I was wondering if the attempt to introduce a change to the DB that would violate unique names would raise an exception anyway, i.e. are our if statements redundant anyway?

@jdavcs
Copy link
Member

jdavcs commented Sep 17, 2024

Also, with this statement, I think you don't need to check params.name != quota.name in the elif clause anymore.

I think we should not change this in a bug fix.

I think it's part of the bug fix: we've effectively moved that check into the statement filtering clause, so we don't need to check it again.

But I think you are right as long as we assume that we have unique names. I was wondering if the attempt to introduce a change to the DB that would violate unique names would raise an exception anyway, i.e. are our if statements redundant anyway?

We can assume that: there's a unique constraint on that field. We could delegate that to the database; however, that's a little more involved. You'd wrap the session.execute in a try/except block, and you'd need to account for different databases to be certain that it's the unique constraint that's been violated, and not some other database error. It could be done like this with this determining that the constraint was violated. But I think for what we need here, the current approach is simpler and is sufficient.

@jdavcs
Copy link
Member

jdavcs commented Sep 18, 2024

@bernt-matthias Everything looks good, thanks! Would you mind rebasing to get rid of the last empty commit (for a cleaner history)?

bernt-matthias and others added 4 commits September 19, 2024 09:39
A [quota update via API](https://github.com/galaxyproject/galaxy/blob/67b4a69c1b36eec4dc5871c5eeb97b6bdea8a288/lib/galaxy/webapps/galaxy/services/quotas.py#L85)
requires name or quota to be set, but the [manager](https://github.com/galaxyproject/galaxy/blob/67b4a69c1b36eec4dc5871c5eeb97b6bdea8a288/lib/galaxy/managers/quotas.py#L119)
requires a name to be set.

If one wants to change just the description of a quota the used select statement
gets the quota itself and the elif branch hits resulting in an
exception.

With the change one can change just the description, but one still needs
to specify the name of the quota. We could change this such that also in
the manager the name of the quota needs to be specified.
Co-authored-by: Marius van den Beek <[email protected]>
@jdavcs jdavcs merged commit 4a85cb3 into galaxyproject:release_24.1 Sep 19, 2024
48 of 50 checks passed
Copy link

This PR was merged without a "kind/" label, please correct.

@bernt-matthias bernt-matthias deleted the topic/quota-desctiption-update branch September 19, 2024 14:55
@nsoranzo
Copy link
Member

It looks to me that this ended up being more a refactoring than a bugfix? Should the PR title be updated, as it ends up in the release notes?

@bernt-matthias
Copy link
Contributor Author

It's a mix, but in my opinion more a bugfix, since we changed behavior.

bernt-matthias added a commit to bernt-matthias/galaxy that referenced this pull request Oct 23, 2024
this should make the quota manager a bit more siltent when
updating quotas, i.e. only message when something is changed

In galaxyproject#18775 (comment)
it was suggested to remove all messages, but I find it quite useful
when using bioblend.
bernt-matthias added a commit to bernt-matthias/galaxy that referenced this pull request Oct 23, 2024
this should make the quota manager a bit more siltent when
updating quotas, i.e. only message when something is changed

In galaxyproject#18775 (comment)
it was suggested to remove all messages, but I find it quite useful
when using bioblend.
bernt-matthias added a commit to bernt-matthias/galaxy that referenced this pull request Oct 23, 2024
this should make the quota manager a bit more siltent when
updating quotas, i.e. only message when something is changed

In galaxyproject#18775 (comment)
it was suggested to remove all messages, but I find it quite useful
when using bioblend.
bernt-matthias added a commit to bernt-matthias/galaxy that referenced this pull request Oct 23, 2024
this should make the quota manager a bit more siltent when
updating quotas, i.e. only message when something is changed

In galaxyproject#18775 (comment)
it was suggested to remove all messages, but I find it quite useful
when using bioblend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants