def insert_errors(psql_db, file_id, export_event_id, errors):
    transfer_status_id = None
    try:
        psql_db.execute('\n            insert into transfer_status\n            values (default, %s)\n            returning transfer_status_id\n        ', [str(errors)])
        (transfer_status_id,) = psql_db.fetchone()
    except psycopg2.IntegrityError:
        psql_db.execute('\n            select transfer_status_id\n            from transfer_status\n            where transfer_status_message = %s\n        ', [str(errors)])
        (transfer_status_id,) = psql_db.fetchone()
    if (transfer_status_id is None):
        print('Unable to create or get transfer_status_id for following error')
        print(str(errors))
    try:
        psql_db.execute("\n            update file_export set\n              when_transferred = now(),\n              transfer_status = 'failed permanent',\n              transfer_status_id = %s\n            where export_event_id = %s\n              and file_id = %s\n        ", [transfer_status_id, export_event_id, file_id])
    except Exception as e:
        print(e)
def insert_errors(psql_db, file_id, export_event_id, errors):
    transfer_status_id = None
    try:
        psql_db.execute('\n            insert into transfer_status\n            values (default, %s)\n            returning transfer_status_id\n        ', [str(errors)])
        (transfer_status_id,) = psql_db.fetchone()
    except psycopg2.IntegrityError:
        psql_db.execute('\n            select transfer_status_id\n            from transfer_status\n            where transfer_status_message = %s\n        ', [str(errors)])
        (transfer_status_id,) = psql_db.fetchone()
    if (transfer_status_id is None):
        print('Unable to create or get transfer_status_id for following error')
        print(str(errors))
    try:
        psql_db.execute("\n            update file_export set\n              when_transferred = now(),\n              transfer_status = 'failed permanent',\n              transfer_status_id = %s\n            where export_event_id = %s\n              and file_id = %s\n        ", [transfer_status_id, export_event_id, file_id])
    except Exception as e:
        print(e)