Raise exception if history can’t be written

This is fiendishly difficult error to discover on your own.

It’s caused when, during the creation of a row in the database, you run
a query on the same table, or a table that joins to the table you’re
inserting into. What I think is happening is that the database is forced
to flush the session before running the query in order to maintain
consistency.

This means that the session is clean by the time the history stuff comes
to do its work, so there’s nothing for it to copy into the history
table, and it silently fails to record history.

Hopefully raising an exception will:
- prevent this from failing silently
- save whoever comes across this issue in the future a whole load of
  time
This commit is contained in:
Chris Hill-Scott
2019-03-06 08:37:55 +00:00
parent ab22a3d88c
commit c257ec105c
3 changed files with 26 additions and 4 deletions

View File

@@ -838,6 +838,16 @@ def test_dao_fetch_todays_stats_for_all_services_can_exclude_from_test_key(notif
assert stats[0].count == 2
@freeze_time('2001-01-01T23:59:00')
def test_dao_suspend_service_with_no_api_keys(notify_db_session):
service = create_service()
dao_suspend_service(service.id)
service = Service.query.get(service.id)
assert not service.active
assert service.name == service.name
assert service.api_keys == []
@freeze_time('2001-01-01T23:59:00')
def test_dao_suspend_service_marks_service_as_inactive_and_expires_api_keys(notify_db_session):
service = create_service()