Skip to content

CreateMetaDataBulk does not support the index attribute

Sentry Issue: ARKINDEX-BACKEND-V7

UniqueViolation: duplicate key value violates unique constraint "documents_metadata_element_id_name_index_b9ba6f8d_uniq"
DETAIL:  Key (element_id, name, index)=(d0134956-53a7-4946-a443-52edc77c7607, NEO_PC_NAISSANCE, 0) already exists.

  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

IntegrityError: duplicate key value violates unique constraint "documents_metadata_element_id_name_index_b9ba6f8d_uniq"
DETAIL:  Key (element_id, name, index)=(d0134956-53a7-4946-a443-52edc77c7607, NEO_PC_NAISSANCE, 0) already exists.

(19 additional frame(s) were not displayed)
...
  File "django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  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)

There are two ways to reproduce:

# First create a metadata with index 0
cli.request('CreateMetaDataBulk', id=ELEMENT_ID, body={
   "metadata_list": [
       {
           "type": "text",
           "name": "a",
           "value": "first",
       }
   ]
})

# This should create a metadata with index 1, but instead fails
cli.request('CreateMetaDataBulk', id=ELEMENT_ID, body={
   "metadata_list": [
       {
           "type": "text",
           "name": "a",
           "value": "second",
       }
   ]
})
# This always fails
cli.request('CreateMetaDataBulk', id=ELEMENT_ID, body={
   "metadata_list": [
       {
           "type": "text",
           "name": "a",
           "value": "first",
       },
       {
           "type": "text",
           "name": "a",
           "value": "second",
       }
   ]
})
Edited by Erwan Rouchet