Skip to content

Commit

Permalink
Merge pull request #957 from aoghina/master
Browse files Browse the repository at this point in the history
Fix for flask/SQLAlchemy: commit on save (but not when using Pyramid)
  • Loading branch information
omab authored Jul 18, 2016
2 parents c0ea7c4 + 88dce26 commit 6bf0666
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions social/apps/pyramid_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion social/storage/sqlalchemy_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, *args, **kwargs):


class SQLAlchemyMixin(object):
COMMIT_SESSION = True

@classmethod
def _session(cls):
raise NotImplementedError('Implement in subclass')
Expand All @@ -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
Expand Down

0 comments on commit 6bf0666

Please sign in to comment.