-
Notifications
You must be signed in to change notification settings - Fork 149
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
a fix for duplicate alias problem #3010
Conversation
@bhearsum @gabrielBusta I am seeing that one of the tests failed for the PR 😵💫. I had used the same function which has been used for rules. How should I change the function for the test to pass? |
I can see that the failure is a bit confusing -- this is actually a failure in the Python file formatting - not in any test.
In addition to fixing that, it would be good to add tests for this in https://github.com/mozilla-releng/balrog/blob/main/tests/admin/views/test_rules.py (we already have a number of tests for these endpoints that should be a good model for new ones). |
@bhearsum How should I approach fixing the python formatting issue? How should I check if the files have formatting issues? I am thinking of adding a test similar to the test for checking alias in rules class |
You can use black to format the Python files correctly. |
I have formatted the code but some tests still fail |
Please have a look through the linked log for any errors that are still showing up. |
I checked for errors but only warnings are being shown. I have formatted all the files using black, so it can be some other issue which I am not able to figure out from the logs 😢 |
Sorry, this shouldn't be so hard! The log shown by github is incomplete; you can see the full test log if you "View logs in Taskcluster". In the full log, I see
...which doesn't tell you much! I wonder if that's related to the new file you are adding? I would suggest not including |
Hii @bhearsum @gbrownmozilla , the checks have passed, can you please review the PR? Should I do some changes to it? |
tests/admin/views/test_rules.py
Outdated
@@ -2834,3 +2834,14 @@ def testCannotRevokeOtherUsersSignoffAsNormalUser(self): | |||
ret = self._delete("/scheduled_changes/rules/3/signoffs", username="julie", qs={"username": "mary"}) | |||
self.assertEqual(ret.status_code, 403, ret.get_data()) | |||
self.assertEqual(ret.mimetype, "application/json") | |||
|
|||
def testScheduledChangeWithDuplicateAlias(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not quite right, unfortunately. It is testing the /rules
view - which is already covered by
balrog/tests/admin/views/test_rules.py
Line 540 in 6493a9e
ret = self._post( |
You should be adding at least two tests:
- One that validates a POST to
/scheduled_changes/rules
, and one that validates a POST to/scheduled_changes/rules/:sc_id
. The first could be modeled afterbalrog/tests/admin/views/test_rules.py
Line 2161 in 6493a9e
def testAddScheduledChangeNewRuleWithoutUpdateType(self): balrog/tests/admin/views/test_rules.py
Line 2251 in 6493a9e
@mock.patch("time.time", mock.MagicMock(return_value=300))
In both cases the request should a result in a 400 if any of the following are true:
- The alias exists in any row in the
rules
table - The alias exists in any row in the
rule_scheduled_changes
table that meets both the following conditions:complete
is Falsechange_type
isinsert
orupdate
(This may require additional changes to rules.py
as well - please let me know if you have any questions.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll start working on updating the test 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhearsum I have a doubt regarding this -
How do I select the required data in the rule_scheduled_change
table? for eg-
for the rules
table we have the getAlias
function defined to get the rule with the given alias but for rule_scheduled_changes
I am not able to figure out how should I select the data with a given alias.
and also does the column scheduled_by
denote the alias for the rule_scheduled_changes
table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhearsum I have a doubt regarding this - How do I select the required data in the
rule_scheduled_change
table? for eg- for therules
table we have thegetAlias
function defined to get the rule with the given alias but forrule_scheduled_changes
I am not able to figure out how should I select the data with a given alias.
The scheduled_changes
table is accessible through dbo.rules.scheduled_changes
(You can see an example query in the tests
balrog/tests/admin/views/test_rules.py
Line 2012 in 6d46207
r = dbo.rules.scheduled_changes.t.select().where(dbo.rules.scheduled_changes.sc_id == 8).execute().fetchall() |
and also does the column
scheduled_by
denote the alias for therule_scheduled_changes
table?
No -- scheduled_by
is the person who scheduled the change :). The alias is in the base_alias
column in the scheduled changes table (apologies -- I forgot about that detail when I posted the earlier comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok got it! 😄
@bhearsum @gbrownmozilla I have added the tests for the code. Can you please have a look and tell me if it needs some changes? |
It looks like you're making progress. The tests that you added looks fine to me, but you need to cover some additional cases still:
|
Ok got it, so I'd be adding two more tests for it then 👍 |
@bhearsum are the changes fine? |
src/auslib/web/admin/views/rules.py
Outdated
return problem(400, "Bad Request", "Rule with alias exists.") | ||
|
||
if alias is not None: | ||
scheduled_rule_with_alias = dbo.rules.scheduled_changes.t.select().where(dbo.rules.scheduled_changes.base_alias == alias).execute().fetchall() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and the similar block below) are missing the conditions I called out in #3010 (comment):
- complete is False
- change_type is insert or update
@godplayer56 - is this ready for another look? If so, please use the "Re-request review button" in the Reviewers list. |
I am trying to resolve the post issues right now. I'll use it as soon as I am done resolving the issue 👍 |
@bhearsum I have added assertions that confirm that the tests are failing for the right reason 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like something is not quite complete or right here. In my local database I already have an alias of firefox-release
, but I can still scheduled a change to add one on https://localhost:9000/rules/364, which is accepted.
src/auslib/web/admin/views/rules.py
Outdated
@@ -260,6 +260,24 @@ def _post(self, transaction, changed_by): | |||
if what.get("fallbackMapping") is not None and len(fallback_mapping_values) != 1: | |||
return problem(400, "Bad Request", "Invalid fallbackMapping value. No release name found in DB") | |||
|
|||
alias = what.get("base_alias", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is that in this part of the view this needs to be referred to as alias
(not base_alias
). I suggest you try printing out what
and making a web request to confirm this.
tests/admin/views/test_rules.py
Outdated
"mapping": "c", | ||
"update_type": "minor", | ||
"sc_data_version": 1, | ||
"base_alias": "TestDuplicateAlias3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also try simulating a request like this on https://localhost:9000/rules/364 by adding an alias and clicking the Save button - take a dlook at what the the Request JSON looks like in the Developer Tools. If it doesn't use base
neither should you in these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got base_alias from the scheduledChangesTable because in some instances it referred to base_alias instead of alias 😅 . Can you provide me with authorization so I can see what a post request looks like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated all the files to use alias
instead of base_alias
. Though I can't confirm if the issue is now resolved because I don't have authorization for making updates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be fully authorized in your local development environment...
In any case, I can assure you that the admin API doesn't use base
in these requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now - thank you!
This reverts commit 994bd6a.
This pull request tries to fix the duplicate-alias issue #2942