From 4644611cc8ce2681a29bd2d5237242f143a9115c Mon Sep 17 00:00:00 2001 From: Carlin MacKenzie Date: Fri, 8 Nov 2024 16:11:52 +0100 Subject: [PATCH] domains: only flush if data not persisted --- invenio_accounts/datastore.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/invenio_accounts/datastore.py b/invenio_accounts/datastore.py index 2d8e7c65..98808247 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,10 +76,11 @@ 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() - if model: + # add the ID to the model from the DB if needed + if not inspect(model).persistent: + self.db.session.flush() + if isinstance(model, User): current_db_change_history.add_updated_user(sid, model.id) elif isinstance(model, Role):