[Python-modules-commits] [python-social-auth] 71/131: Add atomic transaction around social_auth creation
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:17:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.20
in repository python-social-auth.
commit ef5394f048304cd139da4da03e43bc1d554d309f
Author: Max Arnold <arnold.maxim at gmail.com>
Date: Thu Jul 14 11:30:38 2016 +0700
Add atomic transaction around social_auth creation
Cherry-pick of https://github.com/omab/python-social-auth/pull/770
---
social/storage/django_orm.py | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/social/storage/django_orm.py b/social/storage/django_orm.py
index 8d9e672..637dd23 100644
--- a/social/storage/django_orm.py
+++ b/social/storage/django_orm.py
@@ -1,6 +1,7 @@
"""Django ORM models for Social Auth"""
import base64
import six
+from django.db import transaction
from social.storage.base import UserMixin, AssociationMixin, NonceMixin, \
CodeMixin, BaseStorage
@@ -96,7 +97,16 @@ class DjangoUserMixin(UserMixin):
def create_social_auth(cls, user, uid, provider):
if not isinstance(uid, six.string_types):
uid = str(uid)
- return cls.objects.create(user=user, uid=uid, provider=provider)
+ if hasattr(transaction, 'atomic'):
+ # In Django versions that have an "atomic" transaction decorator / context
+ # manager, there's a transaction wrapped around this call.
+ # If the create fails below due to an IntegrityError, ensure that the transaction
+ # stays undamaged by wrapping the create in an atomic.
+ with transaction.atomic():
+ social_auth = cls.objects.create(user=user, uid=uid, provider=provider)
+ else:
+ social_auth = cls.objects.create(user=user, uid=uid, provider=provider)
+ return social_auth
class DjangoNonceMixin(NonceMixin):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git
More information about the Python-modules-commits
mailing list