strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
https://strapi.io
Other
62.68k stars 7.87k forks source link

Duplicating entries allows records to bypass uniqueness checks #20490

Closed Nniol closed 6 days ago

Nniol commented 2 months ago

Bug report

Required System information

Describe the bug

We have created a schema which is unique fields set to true for two fields. Is we choose Duplicate Item Line x then we get the warning message saying we have unique checks in place for some fields. However if we do nothing and just click Save then the record saves and can be published bypassing any uniqueness checks hence causing issues in the solution.

Steps to reproduce the behavior

  1. Create an pickem_group , save and publish
  2. Then choose Duplicate Item on line 2 (Picture 1)
  3. You get a warning message, good (Picture 2)
  4. Click Create
  5. Click Save
  6. Go to list view and see duplicate values for both pickemGroupId and name which are unique according to the schema (Picture 3)
  7. Click back on item
  8. Click Publish
  9. Still no warning or stop

Expected behaviour

At step 5 a warning should appear preventing the creation of the record

Screenshots

Picture 1 image

Picture 2 image

Picture 3 image

Code snippets

pickem_group schema:

{ "kind": "collectionType", "collectionName": "pickem_groups", "info": { "singularName": "pickem-group", "pluralName": "pickem-groups", "displayName": "Pickem Group", "description": "" }, "options": { "draftAndPublish": true }, "attributes": { "pickemGroupId": { "type": "string", "required": true, "unique": true, "minLength": 5, "regex": "^[a-zA-Z0-9-]+$" }, "name": { "type": "string", "unique": true, "required": true, "minLength": 5 }, "pickemOpens": { "type": "datetime", "required": true }, "pickemCloses": { "type": "datetime", "required": true }, "event": { "type": "relation", "relation": "manyToOne", "target": "api::event.event", "inversedBy": "pickem_groups" }, "races": { "type": "relation", "relation": "oneToMany", "target": "api::race.race", "mappedBy": "pickem_group" } } }

Additional context

Add any other context about the problem here.

hanpaine commented 1 month ago

This has been fixed on Strapi 5 and a fix will be ported to V4 in coming weeks