Skip to content

Commit

Permalink
bug: add handler for handling changed domain
Browse files Browse the repository at this point in the history
remove setting of role.id as the added flush() will add the ID from DB
  • Loading branch information
carlinmack committed Nov 7, 2024
1 parent 24f9ac2 commit b29a85d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions invenio_accounts/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ 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:
if isinstance(model, User):
current_db_change_history.add_updated_user(sid, model.id)
elif isinstance(model, Role):
current_db_change_history.add_updated_role(sid, model.id)
elif isinstance(model, Domain):
current_db_change_history.add_updated_domain(sid, model.id)
elif uid:
# Deprecated - use model param instead (still used in e.g.
# UserFixture pytest-invenio)
Expand All @@ -91,20 +96,12 @@ def mark_changed(self, sid, uid=None, rid=None, model=None):
def update_role(self, role):
"""Updates roles."""
role = self.db.session.merge(role)
# This works because role defines it's own id - for users
# the same doesn't work because id is assigned on commit which
# hasn't happened yet.
self.mark_changed(id(self.db.session), model=role)
return role

def create_role(self, **kwargs):
"""Creates and returns a new role from the given parameters."""
role = super().create_role(**kwargs)
# This works because role defines it's own id - for users
# the same doesn't work because id is assigned on commit which
# hasn't happened yet.
if role.id is None:
role.id = role.name
self.mark_changed(id(self.db.session), model=role)
return role

Expand Down

0 comments on commit b29a85d

Please sign in to comment.