Skip to content

ref(quick-start): Replace 'record' with 'create_or_update' in 'record_new_project' #86663

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/sentry/receivers/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ def record_new_project(project, user=None, user_id=None, origin=None, **kwargs):
),
)

success = OrganizationOnboardingTask.objects.record(
_, created = OrganizationOnboardingTask.objects.create_or_update(
Copy link
Member

Choose a reason for hiding this comment

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

Since this signal is sent only on project creation, we don't need to do create_or_update, we can just do create and save ourselves multiple db calls which would be executed in create_or_update

Copy link
Member Author

Choose a reason for hiding this comment

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

so we just do the try catch and if it fails, we record the second platform? if it fails I would like to still check if the project was recorded before saving the second platform, because it can fail for other reasons too and not only integrity right?

Copy link
Member

Choose a reason for hiding this comment

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

Ohh true true, my mistake...

So the overall flow needs to be:

  • we either try to create or update, or we try to create and catch integrity error
  • if it is not created or the error is caught- we try to create or update second platform object

Copy link
Member

Choose a reason for hiding this comment

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

So to sum it up, your logic is good as it is, sorry Pri :/

Copy link
Member Author

Choose a reason for hiding this comment

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

no problem 🙂 in this case, mind approving the PR? 🙏

organization_id=project.organization_id,
task=OnboardingTask.FIRST_PROJECT,
user_id=user_id,
status=OnboardingTaskStatus.COMPLETE,
project_id=project.id,
values={
"user_id": user_id,
"status": OnboardingTaskStatus.COMPLETE,
"project_id": project.id,
},
)
if not success:
# if we updated the task "first project", it means that it already exists and now we want to create the task "second platform"
if not created:
# Check if the "first project" task already exists and log an error if needed
first_project_task_exists = OrganizationOnboardingTask.objects.filter(
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 that it is now guaranteed that the first project task exists, as create_or_update is definitely called.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes 🙌

organization_id=project.organization_id, task=OnboardingTask.FIRST_PROJECT
Expand All @@ -117,12 +120,14 @@ def record_new_project(project, user=None, user_id=None, origin=None, **kwargs):
level="warning",
)

OrganizationOnboardingTask.objects.record(
OrganizationOnboardingTask.objects.create_or_update(
Copy link
Member

@vgrozdanic vgrozdanic Mar 10, 2025

Choose a reason for hiding this comment

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

Why is this called here, is it still needed?

My mistake, this needs to be called here

Copy link
Member Author

Choose a reason for hiding this comment

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

we do not need to look for a cache here, do we?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, this won't be called that often

organization_id=project.organization_id,
task=OnboardingTask.SECOND_PLATFORM,
user_id=user_id,
status=OnboardingTaskStatus.COMPLETE,
project_id=project.id,
values={
"user_id": user_id,
"status": OnboardingTaskStatus.COMPLETE,
"project_id": project.id,
},
)
analytics.record(
"second_platform.added",
Expand Down
Loading