Skip to content

Duplicate UID doesn't show the respective error in API call #9168

@anubhavranjan

Description

@anubhavranjan

Bug report

Describe the bug

I have created a Collection in which I have a field Slug of type UID.
At present, if I try to add data having the same UID in the Collection using API, it throws Internal Server Error but doesn’t even mention the error about UID.

{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "An internal server error occurred"
}

Whereas when the same insertion is tried from the Admin, I get to see the Unavailable result.
image

Steps to reproduce the behavior

  1. Go to Content-Types builder
  2. Add a new Collection of your Choice
  3. Add a new field of type UID
  4. Once done, try adding a new value to the Collection.
  5. Again try to add the same value and it will show you Unavailable error in the Admin
  6. Try to use the API call and see if you can insert the same values
  7. You will get the above-mentioned error

Expected behavior

Expected to get the API response as it's sent in the Admin:

{
    "statusCode":400,
    "error":"Bad Request",
    "message":"Invalid input data. Please verify unique constraints"
}

Code snippets


{
  "kind": "collectionType",
  "collectionName": "user_lists",
  "info": {
    "name": "UserList",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "Name": {
      "type": "string"
    },
    "IsPrivate": {
      "type": "boolean",
      "default": false
    },
    "Description": {
      "type": "string"
    },
    "Slug": {
      "type": "uid"
    },
    "Items": {
      "via": "List",
      "collection": "user-list-item"
    },
    "User": {
      "via": "Lists",
      "model": "user"
    }
  }
}

System

  • Node.js version: 14.15.1
  • Strapi version: 3.4.3
  • Database: PostgreSQL
  • Operating system: Ubuntu 20.04

Additional context

I tried reproducing the same in Local and I can see the same error in my Local Environment

  • Node.js version: 14.15.1
  • NPM version: 6.14.8
  • Strapi version: 3.4.3
  • Database: PostgreSQL
  • Operating system: Windows 10 20H2

Checked the PostgreSQL logs and can see the same error:

ERROR:  duplicate key value violates unique constraint "user_lists_slug_unique"
DETAIL:  Key ("Slug")=(first-list) already exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundsource: core:databaseSource is core/database packagestatus: pending reproductionWaiting for free time to reproduce the issue, or more information

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions