diff --git a/social/apps/pyramid_app/models.py b/social/apps/pyramid_app/models.py index 2d70e0681..5752f3f51 100644 --- a/social/apps/pyramid_app/models.py +++ b/social/apps/pyramid_app/models.py @@ -24,6 +24,8 @@ 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 621bf4c1f..e48ef64cf 100644 --- a/social/storage/sqlalchemy_orm.py +++ b/social/storage/sqlalchemy_orm.py @@ -28,6 +28,8 @@ def __init__(self, *args, **kwargs): class SQLAlchemyMixin(object): + COMMIT_SESSION = True + @classmethod def _session(cls): raise NotImplementedError('Implement in subclass') @@ -43,7 +45,11 @@ def _new_instance(cls, model, *args, **kwargs): @classmethod def _save_instance(cls, instance): cls._session().add(instance) - cls._flush() + if cls.COMMIT_SESSION: + cls._session().commit() + cls._session().flush() + else: + cls._flush() return instance @classmethod