-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes 🙌 |
||
organization_id=project.organization_id, task=OnboardingTask.FIRST_PROJECT | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My mistake, this needs to be called here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not need to look for a cache here, do we? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
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.
Since this signal is sent only on project creation, we don't need to do
create_or_update
, we can just docreate
and save ourselves multiple db calls which would be executed increate_or_update
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.
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?
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.
Ohh true true, my mistake...
So the overall flow needs to be:
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.
So to sum it up, your logic is good as it is, sorry Pri :/
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.
no problem 🙂 in this case, mind approving the PR? 🙏