HumanSignal/label-studio · critical · LabelStudioDatabaseException

Database error during project creation. Try again.

Error message

Database error during project creation. Try again.

What it means

Generic fallback in ProjectListAPI.perform_create: when saving a new project raises an IntegrityError that is NOT the known duplicate-title constraint, it is converted to LabelStudioDatabaseException with this message. It signals an unexpected database-level failure during project creation.

Source

Thrown at label_studio/projects/api.py:223

        if self.request.method == 'GET' and sparse_fields is not None:
            fields_param = settings.REST_FLEX_FIELDS.get('FIELDS_PARAM', 'fields')
            kwargs[fields_param] = sparse_fields
        return super().get_serializer(*args, **kwargs)

    def get_serializer_context(self):
        context = super(ProjectListAPI, self).get_serializer_context()
        context['created_by'] = self.request.user
        return context

    def perform_create(self, ser):
        try:
            ser.save(organization=self.request.user.active_organization)
        except IntegrityError as e:
            if str(e) == 'UNIQUE constraint failed: project.title, project.created_by_id':
                raise ProjectExistException(
                    'Project with the same name already exists: {}'.format(ser.validated_data.get('title', ''))
                )
            raise LabelStudioDatabaseException('Database error during project creation. Try again.')

    def get(self, request, *args, **kwargs):
        return super(ProjectListAPI, self).get(request, *args, **kwargs)

    @api_webhook(WebhookAction.PROJECT_CREATED)
    def post(self, request, *args, **kwargs):
        return super(ProjectListAPI, self).post(request, *args, **kwargs)


@method_decorator(
    name='get',
    decorator=extend_schema(
        tags=['Projects'],
        summary="List projects' counts",
        parameters=[
            *serializer_to_openapi_params(GetFieldsSerializer),
            *filterset_to_openapi_params(ProjectFilterSet),
        ],

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Check Django/DB logs for the underlying IntegrityError details
  2. Run pending migrations (python label_studio/manage.py migrate)
  3. Verify DB schema matches the installed Label Studio version
  4. Retry the creation after fixing schema/data; escalate with the original traceback
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify DB schema is current
// python label_studio/manage.py migrate --check

Try / catch

try:
    project = await axios.post('/api/projects', payload);
catch (e) {
  if (e.response?.status === 500 && /database/i.test(e.message)) {
    // check server logs for IntegrityError, run migrations, retry once
  } else throw e;
}

Prevention

When it happens

Trigger: POST /api/projects where ser.save() raises IntegrityError for any reason other than 'UNIQUE constraint failed: project.title, project.created_by_id' (e.g. FK constraint violation, other unique constraint, data truncation raising as integrity error in some backends).

Common situations: DB migrations out of sync (missing columns/constraints differing from the code); PostgreSQL vs SQLite constraint message differences; corrupted data or FK mismatched organization/user; running an older DB schema against newer code.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/ec5bbc15f7762bcc. Report an issue: GitHub.