Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for flask/SQLAlchemy: commit on save (but not when using Pyramid) #957

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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