diff options
-rw-r--r-- | scripts/insert_data.py | 21 |
1 files 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__": |