Release 0.67.1#3328
Conversation
* add refactor plan document * add inital adapters and view models, * add some suggested documentation changes
…#3324) * feat: added welcome to learner email once he login for the first time
* fix: 404 on product pages when live=false * fix: prevent metadata generation for non-live product pages
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
| send_welcome_email.delay(request.user.id) | ||
| profile.has_logged_in = True | ||
| profile.save() |
There was a problem hiding this comment.
Bug: A failure during profile.save() after dispatching the send_welcome_email task could cause multiple welcome emails to be sent to a user on subsequent logins.
Severity: MEDIUM
Suggested Fix
Move the send_welcome_email.delay() call to after the profile.save() call has successfully completed. Alternatively, wrap the state change and the task dispatch in a database transaction using transaction.on_commit to ensure the task is only enqueued if the database write is successful. Adding an idempotency check within the send_welcome_email task would also prevent duplicates.
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: authentication/views.py#L104-L106
Potential issue: The `send_welcome_email.delay()` Celery task is dispatched before the
database transaction that sets `profile.has_logged_in = True` is committed.
Specifically, the task is queued at line 104, but the `profile.save()` call that
persists the state change is at line 106. If `profile.save()` fails due to a transient
database error, the `has_logged_in` flag remains `False`. However, the welcome email
task has already been enqueued. On every subsequent login attempt, the `if not
profile.has_logged_in` condition will evaluate to true, causing another welcome email to
be dispatched until the save operation finally succeeds. The `send_welcome_email` task
lacks idempotency checks, so it sends an email every time it is invoked.
Did we get this right? 👍 / 👎 to inform future reviews.
Danielle Frappier
Zaman Afzal
Carey P Gumaer