# Buggy code
def __init__(
    self,
    iss: str,
    typ: str,
    sub: str,
    aud: str,
    exp: dt,
    nbf: dt,
    iat: dt,
    jti: str = None,
    **kwargs,
) -> None:
    self.issuer = iss
    self.type = typ
    self.subject = sub
    self.audience = aud
    self.expiration = exp
    self.not_before = nbf
    self.issued_at = iat
    self.jwt_id = jti

    self.name = kwargs.get("name")
    self.preferred_username = kwargs.get("preferred_username")
    self.email = kwargs.get("email")
    self.provider = kwargs.get("provider")
    self.orgs = kwargs.get("orgs", list())
    self.groups = kwargs.get("groups", list())
    self.roles = kwargs.get("roles", list())
    self.scopes = kwargs.get("scopes", list())
    self.email_verified = kwargs.get("email_verified")
    self.picture = kwargs.get("picture")
    self.customers = kwargs.get("customers")


# Traceback (psycopg2.errors.UniqueViolation)
Oct 15 10:45:04 influx alertad[28913]: 2020-10-15 10:45:04,542 alerta.app[28919]: [ERROR] duplicate key value violates unique constraint "users_email_key"
DETAIL:  Key (email)=(xxxxxx@xxxxx) already exists.
request_id=7f8eab74-9c03-4d36-a92f-c5c0d82b3c6f ip=80.120.197.114
Traceback (most recent call last):
File "/opt/alerta/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/alerta/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/alerta/lib/python3.7/site-packages/flask_cors/decorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
File "/opt/alerta/lib/python3.7/site-packages/alerta/auth/oidc.py", line 135, in openid
user.create()
File "/opt/alerta/lib/python3.7/site-packages/alerta/models/user.py", line 140, in create
return User.from_db(db.create_user(self))
File "/opt/alerta/lib/python3.7/site-packages/alerta/database/backends/postgres/base.py", line 910, in create_user
return self._insert(insert, vars(user))
File "/opt/alerta/lib/python3.7/site-packages/alerta/database/backends/postgres/base.py", line 1389, in _insert
cursor.execute(query, vars)
File "/opt/alerta/lib/python3.7/site-packages/psycopg2/extras.py", line 327, in execute
return super(NamedTupleCursor, self).execute(query, vars)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "users_email_key"
DETAIL:  Key (email)=(xxxxxx@xxxxxxxx) already exists.
Oct 15 10:45:04 influx alertad[28913]: 2020-10-15 10:45:04,541 alerta.app[28919]: [DEBUG] ****************************************

INSERT INTO users (id, name, login, password, email, status, roles, attributes,
create_time, last_login, text, update_time, email_verified)
VALUES ('Cil1aWQ9c2hlZGVuaWdnLG91PVBlb3BsZSxkYz1pbnZlbml1bSxkYz1pbxIEbGRhcA', 'xxxxxxx', 'xxxxxxxxx', '', 'xxxxxxxxxx', 'active', ARRAY['admin']
NULL, '', '2020-10-15T10:45:04.541Z', true)
RETURNING *

**************************************** request_id=7f8eab74-9c03-4d36-a92f-c5c0d82b3c6f ip=xxxxx
Oct 15 10:45:04 influx alertad[28913]: 2020-10-15 10:45:04,540 alerta.app[28919]: [DEBUG] ****************************************
SELECT * FROM users WHERE id='Cil1aWQ9c2hlZGVuaWdnLG91PVBlb3BsZSxkYz1pbnZlbml1bSxkYz1pbxIEbGRhcA'
**************************************** request_id=7f8eab74-9c03-4d36-a92f-c5c0d82b3c6f ip=xxxxx

# Fixed code
def __init__(
    self,
    iss: str,
    typ: str,
    sub: str,
    aud: str,
    exp: dt,
    nbf: dt,
    iat: dt,
    jti: str = None,
    **kwargs,
) -> None:
    self.issuer = iss
    self.type = typ
    self.subject = sub
    self.audience = aud
    self.expiration = exp
    self.not_before = nbf
    self.issued_at = iat
    self.jwt_id = jti

    self.name = kwargs.get("name")
    self.preferred_username = kwargs.get("preferred_username")
    self.email = kwargs.get("email")
    self.provider = kwargs.get("provider")
    self.orgs = kwargs.get("orgs", list())
    self.groups = kwargs.get("groups", list())
    self.roles = kwargs.get("roles", list())
    self.scopes = kwargs.get("scopes", list())
    self.email_verified = kwargs.get("email_verified")
    self.picture = kwargs.get("picture")
    self.customers = kwargs.get("customers")
    self.oid = kwargs.get("oid")