core icon indicating copy to clipboard operation
core copied to clipboard

Duplicate unique content field values - bug

Open yasindilekci opened this issue 10 years ago • 1 comments

Hey,

We’ve found a way to create multiple contents with the same value in the unique field, by bringing back an older version of a content while having another content with that value already.

Let's say we create a new Content Type with an unique field. Afterwards we create a new content with value X and rename it to Y. Now this content has two items in the history: X and Y.

Then we create another content with value X. We now have two different contents: Y and X.

When we open content Y, the one with two items in the history, and bring back X from the history, we will have to different contents with value X which should not be allowed since the field is unique.

Expected Behavior

The 'unique' constraint is added to the field to prevent duplicates. So we expect a warning that should prevent us from bringing back the older version of the content when another content is using that unique value already.

Current Behavior

It allows us to bring back a content from which the unique value already is used in another content. After bringing it back, we have two contents with the same value for the unique field. This behaviour doesn't meet the 'unique' constraint requirement we have on the content field.

Possible Solution

Check if the unique field value already exists in another content upon trying to bring ##back an older version of a content.

Known Workarounds

None.

Steps to Reproduce (for bugs)

  1. Log in to the backend, found at http://demo.dotcms.com/c, with the credentials:

    username: [email protected] password: admin

  2. Click on 'Content Types' on the tab menu

  3. Click on 'Add New Content Type' in the right above corner, and add a new Content Type with the following properties:

  • Type: Content
  • Name: UniqueTitleContent
  • Description: Content with an unique key
  • Site or Folder: demo.dotcms.com
  • Workfow Scheme: Default Scheme
  • Detail Page: - (empty)
  • URL Map Pattern: - (empty)
  1. Click on 'Save' and you should be redirected to the field page of the newly created content.
  2. Click on 'Add New Field' on the right above corner
  3. In the Dropdown list select 'Text' as Display Type with the following values:
  • Label: Title
  • Data Type: Text
  • Validation RegEx: - (empty)
  • Default Value: - (empty)
  • Hint: Unique title
  1. Check the Required, User Searchable, System Indexed, Show in listing and Unique checkboxes.
  2. Click on 'Save Field'
  3. Click on 'Content' on the tab menu
  4. Click on 'Add New Content'
  5. A pop-up should appear, click on 'UniqueTitleContent'
  6. You should be redirected to a new page where you can fill in a title. In the title textbox write down: Hello World
  7. Click on 'Save / Publish'
  8. Click again on 'Add New Content' and repeat the same steps and try to add Hello Word as title, you should receive an unique value warning. This behaviour is correct since the title field is unique.
  9. Click on 'Cancel'.
  10. Click on the created 'UniqueTitleContent' content, click on lock for editing, rename the title to John Doe and click on 'Save / Publish'
  11. Now we have a 'UniqueTitleContent' content with title John Doe
  12. Click again on 'Add New Content' and add another 'UniqueTitleContent' content, but this time with the title Hello World (like we did previously). Click on 'Save/Publish'.

We now have 2 different 'UniqueTitleContent' contents with the titles Hello World and John Doe

  1. Click on the John Doe content. On the new page click on the tab 'History'.
  2. You will see two different versions: Hello World, this is the old value of the title for this content, and John Doe, which is the current value of this content.
  3. Now click on 'Bring Back' for the Hello World title and press OK in the dialog.
  4. Click 'Cancel'

Now you should see two different 'UniqueTitleContent' contents with the same title, both Hello World. This shouldn't be possible since the title field is marked as unique.

Context

I try to prevent duplicate content field values by adding the 'unique' constraint to it. But it's still possible to have duplicate unique field values by bringing back an older version of a content.

Your Environment

  • dotCMS version used: 3.6 and 3.7
  • Browser Name and version: Chrome 53.0.2785.143 m
  • Operating System and version: Windows 10 Pro 64-Bit
  • Application Server and version: Apache Tomcat 8.0.18
  • Java Brand and version: Oracle, 1.8.0_101
  • Database and version: Default H2 database

yasindilekci avatar Oct 11 '16 09:10 yasindilekci

This issue has been automatically marked as stale because it has not had activity within the past 90 days. It will be closed in 30 days no further activity occurs. Thank you.

stale[bot] avatar Sep 28 '19 23:09 stale[bot]