Fixes race condition issue when re-saving facebook access token #164
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.
Hi!
We're spawning a celery task when a user signs in, in order to re-fetch some data from facebook. In this task we use the access token from socialregistration.contrib.facebook. Sometimes we're getting an error because the user doesn't have an access token (even though they've had it on previous sign ins).
I believe this fixes the issue with non existing access tokens (since the delete & insert is replaced with an update if the access token already exists).
There's still a race condition where our task might get the old access token, but that is much less of an issue compared to not getting an access token at all. This could be solved by calling the django.contrib.auth.login() function after the socialregistration.signals.login is triggered. As far as I can tell this change should be OK with the contrib.facebook, but I'm not enough familiar with the code to know if this would break any other services, or any API promises.