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

Add activate user task #556

Merged
merged 3 commits into from
Jul 17, 2024
Merged

Conversation

michelletran-codecov
Copy link
Contributor

@michelletran-codecov michelletran-codecov commented Jul 11, 2024

This adds a task that links a user to an account. In particular, we want this to be called in the NotifyTask if the organization has should_attempt_author_auto_activation enabled.

Why is this a different task? This is mainly to isolate the models to avoid using SQLAlchemy. In the ideal scenario, we would add this association directly in the activate_user method. The second best place would be in the New User Activation Task. However, this would mean porting the code to Django, and it is a big lift for now. So, adding this new task to just do the account-user association. In the future, this task could potentially be the one we migrate the New User Activation Task to.

ticket ref: codecov/engineering-team#1993
depends on: codecov/shared#284

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-staging
Copy link

codecov-staging bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #556   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files         420      422    +2     
  Lines       35397    35468   +71     
=======================================
+ Hits        34517    34588   +71     
  Misses        880      880           
Flag Coverage Δ
integration 97.51% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.51% <100.00%> (+<0.01%) ⬆️
unit 97.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.59% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.74% <ø> (ø)
Files Coverage Δ
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/activate_account_user.py 100.00% <100.00%> (ø)
tasks/notify.py 98.28% <100.00%> (+<0.01%) ⬆️
tasks/tests/unit/test_activate_account_user.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)

@codecov-qa
Copy link

codecov-qa bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.51%. Comparing base (7a265f3) to head (a976697).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #556   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files         420      422    +2     
  Lines       35397    35468   +71     
=======================================
+ Hits        34517    34588   +71     
  Misses        880      880           
Flag Coverage Δ
integration 97.51% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.51% <100.00%> (+<0.01%) ⬆️
unit 97.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.59% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.74% <ø> (ø)
Files Coverage Δ
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/activate_account_user.py 100.00% <100.00%> (ø)
tasks/notify.py 98.28% <100.00%> (+<0.01%) ⬆️
tasks/tests/unit/test_activate_account_user.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)

Copy link

codecov-public-qa bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.51%. Comparing base (7a265f3) to head (a976697).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #556   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files         420      422    +2     
  Lines       35397    35468   +71     
=======================================
+ Hits        34517    34588   +71     
  Misses        880      880           
Flag Coverage Δ
integration 97.51% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.51% <100.00%> (+<0.01%) ⬆️
unit 97.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.59% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.74% <ø> (ø)
Files Coverage Δ
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/activate_account_user.py 100.00% <100.00%> (ø)
tasks/notify.py 98.28% <100.00%> (+<0.01%) ⬆️
tasks/tests/unit/test_activate_account_user.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.54%. Comparing base (7a265f3) to head (a976697).

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #556   +/-   ##
=======================================
  Coverage   97.53%   97.54%           
=======================================
  Files         451      453    +2     
  Lines       36119    36190   +71     
=======================================
+ Hits        35229    35300   +71     
  Misses        890      890           
Flag Coverage Δ
integration 97.51% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.51% <100.00%> (+<0.01%) ⬆️
unit 97.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.63% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.74% <ø> (ø)
Files Coverage Δ
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/activate_account_user.py 100.00% <100.00%> (ø)
tasks/notify.py Critical 98.28% <100.00%> (+<0.01%) ⬆️
tasks/tests/unit/test_activate_account_user.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)

This change has been scanned for critical changes. Learn more

@michelletran-codecov michelletran-codecov marked this pull request as ready for review July 11, 2024 20:10
@michelletran-codecov michelletran-codecov requested a review from a team July 11, 2024 20:15
user_ownerid=user_ownerid,
org_ownerid=org_ownerid,
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between celery_app.send_task() and self.app.tasks[activate_account_user_task_name].apply_async()?

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 think the main difference between send_task and apply_async is the way to reference the task. apply_async requires the task to be registered on the existing process, whereas send_task requires only then name. Otherwise, they do the same thing (starts running a new task). I'm not entirely sure why send_task was used here. I didn't want to change the existing call, so I left it with send_task, but I think that it can also be called with apply_async.

Copy link
Contributor

@nora-codecov nora-codecov left a comment

Choose a reason for hiding this comment

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

left some questions but I don't think they are blocking ✅

Copy link
Contributor

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

I primarily asking questions here, in order to learn more about the code :-)


new_user_activation_call = mocked_send_task.call_args_list[0]
account_user_activation_call = mocked_send_task.call_args_list[1]
assert new_user_activation_call == call(
Copy link
Contributor

Choose a reason for hiding this comment

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

similar to the difference between send_task and apply_async, what is the difference between these two asserts? would it make sense to use the same patterns for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The asserts deal with the different ways that send_task and apply_async the mocked send_task. Both asserts just check the call args (but the async call adds more stuff, which is why it's more complex).

tasks/tests/unit/test_activate_account_user.py Outdated Show resolved Hide resolved
The main motivation for this task is to have the task use the Django
models exclusively. We can migrate some of the other New User Activation
code to this in the future maybe.
When a user has auto_activate configuration for their user, we want
to also make the trigger to activate_account_user task as well.
@michelletran-codecov michelletran-codecov added this pull request to the merge queue Jul 17, 2024
Merged via the queue into main with commit e9abbde Jul 17, 2024
29 of 30 checks passed
@michelletran-codecov michelletran-codecov deleted the 1993_add_account_activate_task branch July 17, 2024 14:49
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