directus / directus

The flexible backend for all your projects 🐰 Turn your DB into a headless CMS, admin panels, or apps with a custom UI, instant APIs, auth & more.
https://directus.io
Other
28.22k stars 3.93k forks source link

Save as copy not working with autoincrement primary key #15771

Closed lluishi93 closed 1 year ago

lluishi93 commented 2 years ago

Describe the Bug

Save as copy has stopped working. It seems that it fails when creating the new record because Directus is trying to use the existing ID.

To Reproduce

Errors Shown

{
  "errors": [
    {
      "message": "Field has to be unique.",
      "extensions": {
        "code": "RECORD_NOT_UNIQUE",
        "collection": "PRIMARY",
        "field": null,
        "invalid": "2226"
      }
    }
  ]
}

What version of Directus are you using?

9.18.0

What version of Node.js are you using?

16.14.0

What database are you using?

MySQL 5.7

What browser are you using?

Chrome

How are you deploying Directus?

Docker

azrikahar commented 2 years ago

Preface: The field null value is related to #15033, so that should be addressed over there.

This might be related to the change in #14947 (released in 9.18.0), particularly the check for is_generated to delete the primary key during Save as Copy: https://github.com/directus/directus/pull/14947/files#diff-4ca9afb518ec3f7957e6a2723f01f557c177987383e93bda1ce02918b73b27fcR172

as is_generated is false for autoincrement id, at least for Postgres from my local test: chrome_WIxjVJT4Wc

so the id is being sent during save as copy now.

WuGGu commented 2 years ago

Same problem with 9.18.1. Going back to 9.17.4 fixed it for me.

azrikahar commented 2 years ago

Note: #16186 reported this for UUID as well, so it should also be tested alongside autoincrement primary keys.

AaronBeaudoin commented 2 years ago

I feel that this issue deserves more attention. It's been a month now that the "Save as Copy" button just doesn't work. Maybe, at the very least, the button should be removed entirely in the meantime while this issue remains unresolved?

rijkvanzanten commented 1 year ago

Linear: ENG-179

ricricucit commented 1 year ago

so this is supposed to be working, on the cloud version?

this

....because it doesn't (directus, cloud version)

br41nslug commented 1 year ago

@ricricucit Hiding this comment as unrelated as it was answered here https://github.com/directus/directus/pull/10418#issuecomment-1369895194