HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
19.4k stars 2.41k forks source link

duplicate key value violates unique constraint "io_storages_localfilesexportstoragelink_annotation_id_key" DETAIL: Key (annotation_id)=(25) already exists. #5918

Open amira133 opened 5 months ago

amira133 commented 5 months ago

Describe the bug when submitting an annotation show error:

duplicate key value violates unique constraint "io_storages_localfilesexportstoragelink_annotation_id_key"
DETAIL:  Key (annotation_id)=(25) already exists.

To Reproduce Steps to reproduce the behavior: I am new to label studio, I using these step to install label studio:

  1. create a yml file like this:

    
    version: "3.9"
    services:
    nginx:
    build: .
    image: heartexlabs/label-studio:latest
    restart: unless-stopped
    ports:
      - "8080:8085"
      - "8081:8086"
    depends_on:
      - app
    environment:
      - LABEL_STUDIO_HOST=${LABEL_STUDIO_HOST:-}
    #   Optional: Specify SSL termination certificate & key
    #   Just drop your cert.pem and cert.key into folder 'deploy/nginx/certs'
    #      - NGINX_SSL_CERT=/certs/cert.pem
    #      - NGINX_SSL_CERT_KEY=/certs/cert.key
    volumes:
      - ./mydata:/label-studio/data:rw
      - ./deploy/nginx/certs:/certs:ro
      - /shared/public/data:/data:rw
    #   Optional: Override nginx default conf
    #      - ./deploy/my.conf:/etc/nginx/nginx.conf
    command: nginx
    
    app:
    stdin_open: true
    tty: true
    build: .
    image: heartexlabs/label-studio:latest
    restart: unless-stopped
    expose:
      - "8000"
    depends_on:
      - db
    environment:
      - DJANGO_DB=default
      - POSTGRE_NAME=postgres
      - POSTGRE_USER=postgres
      - POSTGRE_PASSWORD=
      - POSTGRE_PORT=5432
      - POSTGRE_HOST=db
      - LABEL_STUDIO_HOST=${LABEL_STUDIO_HOST:-}
      - JSON_LOG=1
      - LABEL_STUDIO_DISABLE_SIGNUP_WITHOUT_LINK=true
      - LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true
    - LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/data
    #      - LOG_LEVEL=DEBUG
    volumes:
      - ./mydata:/label-studio/data:rw
      - /shared/public/data:/data:rw
    command: label-studio-uwsgi
    
    db:
    image: postgres:11.5
    hostname: db
    restart: unless-stopped
    # Optional: Enable TLS on PostgreSQL
    # Just drop your server.crt and server.key into folder 'deploy/pgsql/certs'
    # NOTE: Both files must have permissions u=rw (0600) or less
    #    command: >
    #      -c ssl=on
    #      -c ssl_cert_file=/var/lib/postgresql/certs/server.crt
    #      -c ssl_key_file=/var/lib/postgresql/certs/server.key
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    volumes:
      - ${POSTGRES_DATA_DIR:-./postgres-data}:/var/lib/postgresql/data
      - ./deploy/pgsql/certs:/var/lib/postgresql/certs:ro
      - /shared/public/data:/data:rw
2- call `docker-compose up -d`
3- then add source/target local storage  
4- start annotating images
5- when click submit show error

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 581, in get_or_create return self.get(**kwargs), False File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 435, in get raise self.model.DoesNotExist( io_storages.localfiles.models.LocalFilesExportStorageLink.DoesNotExist: LocalFilesExportStorageLink matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "io_storages_localfilesexportstoragelink_annotation_id_key" DETAIL: Key (annotation_id)=(25) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, kwargs) File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, *kwargs) File "/label-studio/label_studio/./webhooks/utils.py", line 162, in wrap response = func(self, request, args, kwargs) File "/label-studio/label_studio/./tasks/api.py", line 366, in post return super(AnnotationsListAPI, self).post(request, *args, kwargs) File "/usr/local/lib/python3.10/dist-packages/rest_framework/generics.py", line 242, in post return self.create(request, args, kwargs) File "/usr/local/lib/python3.10/dist-packages/rest_framework/mixins.py", line 19, in create self.perform_create(serializer) File "/label-studio/label_studio/./tasks/api.py", line 426, in perform_create annotation = ser.save(extra_args) File "/usr/local/lib/python3.10/dist-packages/rest_framework/serializers.py", line 212, in save self.instance = self.create(validated_data) File "/label-studio/label_studio/./tasks/serializers.py", line 61, in create return super().create(args, kwargs) File "/usr/local/lib/python3.10/dist-packages/rest_framework/serializers.py", line 962, in create instance = ModelClass._default_manager.create(validated_data) File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, *kwargs) File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 453, in create obj.save(force_insert=True, using=self.db) File "/label-studio/label_studio/./tasks/models.py", line 731, in save result = super().save(args, kwargs) File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 739, in save self.save_base(using=using, force_insert=force_insert, File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 787, in save_base post_save.send( File "/usr/local/lib/python3.10/dist-packages/django/dispatch/dispatcher.py", line 180, in send return [ File "/usr/local/lib/python3.10/dist-packages/django/dispatch/dispatcher.py", line 181, in (receiver, receiver(signal=self, sender=sender, named)) File "/usr/local/lib/python3.10/dist-packages/sentry_sdk/integrations/django/signals_handlers.py", line 66, in wrapper return receiver(*args, *kwargs) File "/label-studio/label_studio/./io_storages/localfiles/models.py", line 142, in export_annotation_to_local_files storage.save_annotation(instance) File "/label-studio/label_studio/./io_storages/localfiles/models.py", line 125, in save_annotation LocalFilesExportStorageLink.create(annotation, self) File "/label-studio/label_studio/./io_storages/base_models.py", line 629, in create link, created = cls.objects.get_or_create(annotation=annotation, storage=storage, object_exists=True) File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(args, kwargs) File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 588, in get_or_create return self.create(*params), True File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 453, in create obj.save(force_insert=True, using=self.db) File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 739, in save self.save_base(using=using, force_insert=force_insert, File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 776, in save_base updated = self._save_table( File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 881, in _save_table results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw) File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 919, in _do_insert return manager._insert( File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 1270, in _insert return query.get_compiler(using=using).execute_sql(returning_fields) File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql cursor.execute(sql, params) File "/usr/local/lib/python3.10/dist-packages/sentry_sdk/integrations/django/init.py", line 629, in execute return real_execute(self, sql, params) File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 79, in _execute with self.db.wrap_database_errors: File "/usr/local/lib/python3.10/dist-packages/django/db/utils.py", line 90, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: duplicate key value violates unique constraint "io_storages_localfilesexportstoragelink_annotation_id_key" DETAIL: Key (annotation_id)=(25) already exists.



**Screenshots**
![image](https://github.com/HumanSignal/label-studio/assets/27830573/fb5045d8-fdfd-4e18-aa69-057debd58e2b)

![image](https://github.com/HumanSignal/label-studio/assets/27830573/d22bd76c-0610-45b4-a8d7-9c0e8e997c8f)

**Environment (please complete the following information):**
 - OS: ubuntu 20.04
 - Label Studio Version :1.12.0

**Additional context**
Add any other context about the problem here.
sajarin commented 5 months ago

Thanks for the bug report @amira133 I know it's been a while. Does this issue still happen on the latest version? Are you still facing this issue?

amira133 commented 5 months ago

yes, its occured in version 1.12.1