Skip to content

Commit

Permalink
domains: only flush if data not persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Nov 12, 2024
1 parent 72e7cf1 commit 4644611
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions invenio_accounts/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4644611

Please sign in to comment.