From 62e54fd5b457d67f3f01a35e28eae94d653d9908 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 22 Mar 2024 07:30:34 +0300 Subject: Notify user if identifiers are not consistent. --- scripts/insert_data.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/insert_data.py b/scripts/insert_data.py index a60426a..5926905 100644 --- a/scripts/insert_data.py +++ b/scripts/insert_data.py @@ -290,12 +290,21 @@ def insert_se(# pylint: disable = [too-many-arguments] read_datavalues(filepath, headings, strains).values() for row in psrows)) with dbconn.cursor(cursorclass=DictCursor) as cursor: - while True: - serrors = tuple(take(se_values, 1000)) - if not bool(serrors): - break - print(__format_query__(se_query, serrors)) - cursor.executemany(se_query, serrors) + try: + while True: + serrors = tuple(take(se_values, 1000)) + if not bool(serrors): + break + print(__format_query__(se_query, serrors)) + cursor.executemany(se_query, serrors) + except KeyError as kerr: + print( + ( + f"The following name(s) or identifier(s) do(es) not " + "exist in the database and did not exist in the original " + f"values file: {', '.join(kerr.args)}"), + file=sys.stderr) + return 1 return 0 if __name__ == "__main__": -- cgit v1.2.3