[Python-modules-commits] [python-social-auth] 182/322: Flush sqlalchemy session to get the object ids. Refs #390

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:13:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.10
in repository python-social-auth.

commit a52ee69cc641018bbf32c6fd599a6c30036b3086
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Thu Mar 19 16:28:11 2015 -0300

    Flush sqlalchemy session to get the object ids. Refs #390
---
 examples/pyramid_example/example/auth.py |  4 ++--
 social/apps/pyramid_app/models.py        |  2 --
 social/storage/sqlalchemy_orm.py         | 23 +++++++++++++----------
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/examples/pyramid_example/example/auth.py b/examples/pyramid_example/example/auth.py
index 98526f2..23926fe 100644
--- a/examples/pyramid_example/example/auth.py
+++ b/examples/pyramid_example/example/auth.py
@@ -5,8 +5,8 @@ from social.apps.pyramid_app.utils import backends
 from example.models import DBSession, User
 
 
-def login_user(strategy, user, user_social_auth):
-    strategy.strategy.session_set('user_id', user.id)
+def login_user(backend, user, user_social_auth):
+    backend.strategy.session_set('user_id', user.id)
 
 
 def login_required(request):
diff --git a/social/apps/pyramid_app/models.py b/social/apps/pyramid_app/models.py
index 912cf00..c38bf00 100644
--- a/social/apps/pyramid_app/models.py
+++ b/social/apps/pyramid_app/models.py
@@ -24,8 +24,6 @@ def init_social(config, Base, session):
     app_session = session
 
     class _AppSession(object):
-        COMMIT_SESSION = False
-
         @classmethod
         def _session(cls):
             return app_session
diff --git a/social/storage/sqlalchemy_orm.py b/social/storage/sqlalchemy_orm.py
index edffb27..6c105ed 100644
--- a/social/storage/sqlalchemy_orm.py
+++ b/social/storage/sqlalchemy_orm.py
@@ -3,6 +3,8 @@ import base64
 import six
 import json
 
+import transaction
+
 from sqlalchemy import Column, Integer, String
 from sqlalchemy.exc import IntegrityError
 from sqlalchemy.types import PickleType, Text
@@ -22,8 +24,6 @@ class JSONType(PickleType):
 
 
 class SQLAlchemyMixin(object):
-    COMMIT_SESSION = True
-
     @classmethod
     def _session(cls):
         raise NotImplementedError('Implement in subclass')
@@ -39,11 +39,18 @@ class SQLAlchemyMixin(object):
     @classmethod
     def _save_instance(cls, instance):
         cls._session().add(instance)
-        if cls.COMMIT_SESSION:
-            cls._session().commit()
-            cls._session().flush()
+        cls._flush()
         return instance
 
+    @classmethod
+    def _flush(cls):
+        try:
+            cls._session().flush()
+        except AssertionError:
+            with transaction.manager as manager:
+                print "COMMIT 5"
+                manager.commit()
+
     def save(self):
         self._save_instance(self)
 
@@ -84,11 +91,7 @@ class SQLAlchemyUserMixin(SQLAlchemyMixin, UserMixin):
     @classmethod
     def disconnect(cls, entry):
         cls._session().delete(entry)
-        try:
-            cls._session().commit()
-        except AssertionError:
-            import transaction
-            transaction.commit()
+        cls._flush()
 
     @classmethod
     def user_query(cls):

-- 
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