Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: duplicate key value violates unique constraint "keys_key_key" #379

Open
PowerSurj opened this issue Mar 9, 2022 · 3 comments
Open
Labels
bug Something isn't working

Comments

@PowerSurj
Copy link

PowerSurj commented Mar 9, 2022

Issue Summary

Alerta container fails to start (when restarted/redeployed) due to error:

# Create user-defined admin API key.
ERROR: duplicate key value violates unique constraint "keys_key_key"
DETAIL:  Key (key)=(*********secret*********) already exists.

Environment

  • OS: container image alerta/alerta-web:8.7.0

  • Deployment: Helm Chart deployment to Kubernetes

  • For self-hosted, WSGI environment: nginx/uwsgi

  • Database: Postgres, separate data persistent instance, outside of Alerta POD

  • Server config:
    Auth enabled? Yes
    Auth provider? Basic
    Customer views? Yes

  • web UI version: 8.7.0

  • CLI version: 8.7.0

To Reproduce
Steps to reproduce the behavior:

  1. Set values or statically defined matching ENV vars (lookup deployment.yaml)
  • .Values.alertaAdminUsers
  • .Values.alertaAdminKey
  1. Deploy helm chart

  2. restart Alerta POD/Container only. Do not restart Postgres.

Expected behavior
Code should accept the desired idempotent result whereby same admin user is being assigned same key.
Container should be able to recover on restart.

Additional context
Issue is at the
https://github.com/alerta/docker-alerta/blob/master/docker-entrypoint.sh

  # Create user-defined API key, if required
  if [ -n "${ADMIN_KEY}" ]; then
    echo "# Create user-defined admin API key."
    alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --duration "${MAXAGE}"
  fi

the exact syntax of the error seems to originate from psql when trying to insert a record manually
ERROR: duplicate key value violates unique constraint "keys_key_key"

@PowerSurj
Copy link
Author

whilst debugging, I tried adding --force flag to alertad command but it made no difference

alerta@alerta-6cd7bc66d8-2lpmn:/$ alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --force
ERROR: duplicate key value violates unique constraint "keys_key_key"
DETAIL:  Key (key)=(*********secret*********) already exists.

@Rufus111
Copy link

Rufus111 commented Jun 2, 2022

Have a same issue, when launch new container with same db

@FlorianHeigl
Copy link

i had this when i after the first start decided to change the email address from the example. it tried to create the admin user again and somehow this was triggering the duplicate key. (insert vs. update vs. upsert I guess)

@satterly satterly added the bug Something isn't working label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants