diff --git a/invenio_accounts/datastore.py b/invenio_accounts/datastore.py index 2d8e7c65..9deb16c0 100644 --- a/invenio_accounts/datastore.py +++ b/invenio_accounts/datastore.py @@ -14,6 +14,7 @@ from flask import current_app from flask_security import SQLAlchemyUserDatastore, user_confirmed from invenio_db import db +from sqlalchemy import inspect from sqlalchemy.orm import joinedload from .models import Domain, Role, User @@ -75,8 +76,9 @@ def commit(self): def mark_changed(self, sid, uid=None, rid=None, model=None): """Save a user to the changed history.""" - # needed so that we have the id from the DB on the model - self.db.session.flush() + # add the ID to the model from the DB if needed + if not inspect(model).persistent: + self.db.session.flush() if model: if isinstance(model, User):