Skip to content

Commit

Permalink
Expire hid_counter on db_next_hid() call
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Nov 19, 2021
1 parent 29f46af commit 4ea1185
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/galaxy/model/mapping.py
Expand Up @@ -51,6 +51,7 @@ def db_next_hid(self, n=1):
else:
stmt = table.update().where(table.c.id == model.cached_id(self)).values(hid_counter=(table.c.hid_counter + n)).returning(table.c.hid_counter)
next_hid = session.execute(stmt).scalar() - n
session.expire(self, ['hid_counter'])
return next_hid


Expand Down
15 changes: 15 additions & 0 deletions test/unit/data/test_galaxy_mapping.py
Expand Up @@ -920,6 +920,21 @@ def test_can_manage_private_dataset(self):
assert security_agent.can_manage_dataset(u_from.all_roles(), d1.dataset)
assert not security_agent.can_manage_dataset(u_other.all_roles(), d1.dataset)

def test_history_hid_counter_is_expired_after_next_hid_call(self):
u = model.User(email="hid_abuser@example.com", password="password")
h = model.History(name="History for hid testing", user=u)
self.persist(u, h)
state = inspect(h)
assert h.hid_counter == 1
assert 'hid_counter' not in state.unloaded
assert 'id' not in state.unloaded

h._next_hid()

assert 'hid_counter' in state.unloaded # this attribute has been expired
assert 'id' not in state.unloaded # but other attributes have NOT been expired
assert h.hid_counter == 2 # check this last: this causes thie hid_counter to be reloaded

def _three_users(self, suffix):
email_from = f"user_{suffix}e1@example.com"
email_to = f"user_{suffix}e2@example.com"
Expand Down

0 comments on commit 4ea1185

Please sign in to comment.