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

IntegrityError: duplicate key value violates unique constraint "django_celery_results_taskresult_task_id_key" #3836

Closed
sentry-io bot opened this issue Nov 22, 2022 · 2 comments
Assignees
Labels
DEV: backend P1 - important Priority: High impact on UX

Comments

@sentry-io
Copy link

sentry-io bot commented Nov 22, 2022

This issue seems to happen when the task is started too quickly after being sent to the backend, so that the call to task_result = get_task_model(self, task_id) results in an unsaved model, but before it is saved again, the execution of the async task has resulted in that task model already having been inserted in the database.

Sentry Issue: STUDIO-FJB

UniqueViolation: duplicate key value violates unique constraint "django_celery_results_taskresult_task_id_key"
DETAIL:  Key (task_id)=(10b638c5b2a54f008d634a67c23e2fd6) already exists.

  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "newrelic/hooks/database_psycopg2.py", line 64, in execute
    return super(CursorWrapper, self).execute(sql, parameters, *args,
  File "newrelic/hooks/database_dbapi2.py", line 38, in execute
    return self.__wrapped__.execute(sql, parameters,
  File "django_prometheus/db/common.py", line 71, in execute
    return super().execute(*args, **kwargs)

IntegrityError: duplicate key value violates unique constraint "django_celery_results_taskresult_task_id_key"
DETAIL:  Key (task_id)=(10b638c5b2a54f008d634a67c23e2fd6) already exists.

(18 additional frame(s) were not displayed)
...
  File "django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "newrelic/hooks/database_psycopg2.py", line 64, in execute
    return super(CursorWrapper, self).execute(sql, parameters, *args,
  File "newrelic/hooks/database_dbapi2.py", line 38, in execute
    return self.__wrapped__.execute(sql, parameters,
  File "django_prometheus/db/common.py", line 71, in execute
    return super().execute(*args, **kwargs)
@sentry-io
Copy link
Author

sentry-io bot commented Jan 27, 2023

Sentry issue: STUDIO-FYR

@rtibbles
Copy link
Member

rtibbles commented Feb 2, 2023

Fixed in #3934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend P1 - important Priority: High impact on UX
Projects
None yet
Development

No branches or pull requests

2 participants