Stale read in CreateMLClass

Teklia Bot
2025-12-09T08:59:48Z

Sentry Issue: [ARKINDEX-BACKEND-302](https://teklia.sentry.io/issues/7084249553/?referrer=gitlab_integration) ``` UniqueViolation: duplicate key value violates unique constraint "documents_mlclass_name_corpus_id_b4263e79_uniq" DETAIL: ...

Sentry Issue: ARKINDEX-BACKEND-302

UniqueViolation: duplicate key value violates unique constraint "documents_mlclass_name_corpus_id_b4263e79_uniq"
DETAIL:  Key (name, corpus_id)=(List_page, 7f7775fd-3062-4420-8218-ad3212dc3f80) already exists.
  File "django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
  File "psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)

IntegrityError: duplicate key value violates unique constraint "documents_mlclass_name_corpus_id_b4263e79_uniq"
DETAIL:  Key (name, corpus_id)=(List_page, 7f7775fd-3062-4420-8218-ad3212dc3f80) already exists.
(24 additional frame(s) were not displayed)
...
  File "django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
  File "psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)

When CreateMLClass is called twice with the same corpus ID and class name, the second call might not see the class created by the first call because of a stale read.