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

a fix for duplicate alias problem #3010

Merged
merged 22 commits into from
Oct 27, 2023

Conversation

godplayer56
Copy link
Contributor

This pull request tries to fix the duplicate-alias issue #2942

@godplayer56
Copy link
Contributor Author

@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?

@bhearsum
Copy link
Contributor

@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.

[task 2023-10-12T21:23:33.129Z] ERROR: InvocationError for command /builds/worker/checkouts/vcs/.tox/check/bin/black --diff --check scripts src taskcluster tests uwsgi (exited with code 1)

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).

@godplayer56
Copy link
Contributor Author

@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.

[task 2023-10-12T21:23:33.129Z] ERROR: InvocationError for command /builds/worker/checkouts/vcs/.tox/check/bin/black --diff --check scripts src taskcluster tests uwsgi (exited with code 1)

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

@bhearsum
Copy link
Contributor

@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.

[task 2023-10-12T21:23:33.129Z] ERROR: InvocationError for command /builds/worker/checkouts/vcs/.tox/check/bin/black --diff --check scripts src taskcluster tests uwsgi (exited with code 1)

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.

@godplayer56
Copy link
Contributor Author

I have formatted the code but some tests still fail

@bhearsum
Copy link
Contributor

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.

@godplayer56
Copy link
Contributor Author

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 😢

@gbrownmozilla
Copy link
Contributor

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

[task 2023-10-16T10:43:40.522Z] ERROR: InvocationError for command /builds/worker/checkouts/vcs/.tox/check/bin/check-manifest -v . (exited with code 1)

...which doesn't tell you much! I wonder if that's related to the new file you are adding? I would suggest not including settings.json in the PR.

@godplayer56
Copy link
Contributor Author

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

[task 2023-10-16T10:43:40.522Z] ERROR: InvocationError for command /builds/worker/checkouts/vcs/.tox/check/bin/check-manifest -v . (exited with code 1)

...which doesn't tell you much! I wonder if that's related to the new file you are adding? I would suggest not including settings.json in the PR.

Oh I checked the taskcluster logs but I wasn't able to see them 😞 , I'll be careful from now on! Here is what I see in the taskcluster logs even after logging in-
Screenshot from 2023-10-17 18-47-02
For the settings.json file, I will remove it from the PR.

@godplayer56
Copy link
Contributor Author

Hii @bhearsum @gbrownmozilla , the checks have passed, can you please review the PR?

Should I do some changes to it?

@@ -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):
Copy link
Contributor

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

ret = self._post(
.

You should be adding at least two tests:

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 False
    • change_type is insert or update

(This may require additional changes to rules.py as well - please let me know if you have any questions.)

Copy link
Contributor Author

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 👍

Copy link
Contributor Author

@godplayer56 godplayer56 Oct 18, 2023

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?

Copy link
Contributor

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.

The scheduled_changes table is accessible through dbo.rules.scheduled_changes (You can see an example query in the tests

r = dbo.rules.scheduled_changes.t.select().where(dbo.rules.scheduled_changes.sc_id == 8).execute().fetchall()
- and there's many more example of selects in other tests and parts of the codebase).

and also does the column scheduled_by denote the alias for the rule_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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok got it! 😄

@godplayer56
Copy link
Contributor Author

@bhearsum @gbrownmozilla I have added the tests for the code. Can you please have a look and tell me if it needs some changes?

@bhearsum
Copy link
Contributor

@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:

  • A POST to /scheduled_changes/rules with update_type set to update with a duplicate alias
  • A POST to /scheduled_changes/rules/:sc_id with update_type set to insert with a duplicate alias

@godplayer56
Copy link
Contributor Author

Ok got it, so I'd be adding two more tests for it then 👍

@godplayer56
Copy link
Contributor Author

@bhearsum are the changes fine?

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()
Copy link
Contributor

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

tests/admin/views/test_rules.py Show resolved Hide resolved
@bhearsum
Copy link
Contributor

@godplayer56 - is this ready for another look? If so, please use the "Re-request review button" in the Reviewers list.

@godplayer56
Copy link
Contributor Author

@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 👍

@godplayer56
Copy link
Contributor Author

@bhearsum I have added assertions that confirm that the tests are failing for the right reason 👍

@godplayer56 godplayer56 requested a review from bhearsum October 25, 2023 20:22
Copy link
Contributor

@bhearsum bhearsum left a 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.

@@ -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)
Copy link
Contributor

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.

"mapping": "c",
"update_type": "minor",
"sc_data_version": 1,
"base_alias": "TestDuplicateAlias3",
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

@godplayer56 godplayer56 Oct 26, 2023

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

Copy link
Contributor

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.

Copy link
Contributor

@bhearsum bhearsum left a 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!

@bhearsum bhearsum merged commit 994bd6a into mozilla-releng:main Oct 27, 2023
7 checks passed
@godplayer56 godplayer56 deleted the duplicate-alias branch October 28, 2023 18:03
@godplayer56 godplayer56 restored the duplicate-alias branch October 28, 2023 18:03
JohanLorenzo added a commit that referenced this pull request Nov 13, 2023
JohanLorenzo added a commit that referenced this pull request Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants