diff --git a/eidawsauth/eidawsauth.py b/eidawsauth/eidawsauth.py index 7efbb60c3e1c5eb44a045bbb08b12a366a53faa8..c68daa18fb372ff54aea4f9f52de62f0b054ba5b 100644 --- a/eidawsauth/eidawsauth.py +++ b/eidawsauth/eidawsauth.py @@ -123,14 +123,20 @@ def register_privileges(login, fdsn_refs): for ref in fdsn_refs: ref['login'] = login ref['expires_at'] = datetime.datetime.now()+datetime.timedelta(days=1) - cur.execute(""" - select network_id from networks where start_year=%(startyear)s and end_year=%(endyear)s and network=%(networkcode)s; - """, ref) - ref['networkid'] = cur.fetchone()[0] - logging.info("Inserting tupple in %s.eida_temp_users: %s"%(application.config['PRIVILEGEDBNAME'], ref)) - cur.execute(""" - insert into eida_temp_users (network_id, network, start_year, end_year, name, expires_at) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expires_at)s); - """, ref) + logging.info(ref) + sql_request = "select network_id from networks where start_year=%(startyear)s and network=%(networkcode)s" + try: + cur.execute(sql_request, ref) + if cur.rowcount != 1: + logging.info(cur.mogrify(sql_request, ref)) + logging.error("No network found for %s", ref) + ref['networkid'] = cur.fetchone()[0] + logging.info("Inserting tupple in %s.eida_temp_users: %s", application.config['PRIVILEGEDBNAME'], ref) + cur.execute(""" + insert into eida_temp_users (network_id, network, start_year, end_year, name, expires_at) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expires_at)s); + """, ref) + except psycopg2.Error as e: + logging.error(e.pgerror) conn.commit() conn.close()