Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anubhavranjan opened this issue Jan 21, 2021 · 5 comments
Closed

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

anubhavranjan opened this issue Jan 21, 2021 · 5 comments
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:database Source is core/database package status: pending reproduction Waiting for free time to reproduce the issue, or more information

Comments

@anubhavranjan
Copy link

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.
@derrickmehaffy
Copy link
Member

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/how-to-configure-strapi-to-output-errors-related-to-uniqueness-of-the-uid/2244/5

@derrickmehaffy derrickmehaffy added severity: medium If it breaks the basic use of the product but can be worked around source: core:database Source is core/database package status: confirmed Confirmed by a Strapi Team member or multiple community members issue: bug Issue reporting a bug labels Jan 21, 2021
@derrickmehaffy derrickmehaffy added this to To Review in [Experiment] Issue Board via automation Jan 21, 2021
@NellalinkHQ
Copy link

NellalinkHQ commented Jun 8, 2021

Am having this issue currently, I used this workaround, I will check if the field exists in the database by making a get rest request like GET http://localhost:1337/restaurants/505 or maybe with the unique field GET /restaurants?price_gte=505
Then if not found, you can then proceed to use

POST http://localhost:1337/restaurants

Am earnestly waiting for when this update will rollout to fix this issue

@Redleks
Copy link

Redleks commented Dec 7, 2021

Any news ?

@derrickmehaffy derrickmehaffy added status: pending reproduction Waiting for free time to reproduce the issue, or more information and removed status: confirmed Confirmed by a Strapi Team member or multiple community members labels Dec 10, 2021
@cassianogr
Copy link

Is that fixed ?

@derrickmehaffy
Copy link
Member

fixed in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:database Source is core/database package status: pending reproduction Waiting for free time to reproduce the issue, or more information
Projects
Archived in project
Status: Pending SE Review
Development

No branches or pull requests

5 participants