Closed
Conversation
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nathan Levesque <nlevesq@mit.edu>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Levesque <nlevesq@mit.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
Comment on lines
+14
to
+15
| if created: | ||
| sync_hubspot_user(instance) |
There was a problem hiding this comment.
Bug: The post_save signal for syncing new users to Hubspot can trigger a race condition, as the Celery task is queued before the database transaction for the user is committed.
Severity: HIGH
Suggested Fix
Wrap the call to sync_hubspot_user(instance) within a transaction.on_commit() lambda. This will defer the execution of the Celery task until after the database transaction that creates the user has successfully committed, preventing the race condition.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: users/signals.py#L14-L15
Potential issue: The `post_save` signal handler `sync_user_to_hubspot_on_create` queues
a Celery task to sync a new user to Hubspot. This signal fires after the user object is
saved but before the database transaction is committed. This creates a race condition
where the Celery worker may try to fetch the user from the database before the record is
visible, causing the task to fail with an object-not-found error. This is a known
anti-pattern, and other signal handlers in the codebase, such as for products, correctly
use `transaction.on_commit()` to defer the task until after the transaction is complete.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cp-at-mit
annagav
Chris Chudzicki
renovate[bot]
pre-commit-ci[bot]
Dan Subak