From d8742314ced508babf677220115ffb271a3eb1e8 Mon Sep 17 00:00:00 2001 From: Keiran Price Date: Mon, 29 Jul 2019 09:07:37 +0100 Subject: [PATCH] Update update_row_from_id --- common/database_helpers.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/common/database_helpers.py b/common/database_helpers.py index 941c15b5..085f6d8b 100644 --- a/common/database_helpers.py +++ b/common/database_helpers.py @@ -244,18 +244,10 @@ def update_row_from_id(table, id, new_values): :param id: The id of the record :param new_values: A JSON string containing what columns are to be updated """ - log.info(f" Updating row with ID: {id} in {table.__tablename__}") - session = get_icat_db_session() - record = session.query(table).filter(table.ID == id).first() - if record is not None: - record.update_from_dict(new_values) - session.commit() - log.info(" Record updated, closing DB session") - session.close() - return - session.close() - raise MissingRecordError(f" Could not find record in {table.__tablename__} with ID: {id}") - + row = get_row_by_id(table, id) + update_query = UpdateQuery(table, row, new_values) + update_query.execute_query() + def get_rows_by_filter(table, filters): """