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.26k stars 3.94k forks source link

INTERNAL_SERVER_ERROR when trying to add an Image to a collection's removed upload folder. #13585

Closed alikasundara closed 2 years ago

alikasundara commented 2 years ago

Describe the Bug

When adding an image to a collection with a default upload folder configured, the upload will fail with an INTERNAL_SERVER_ERROR (caused by an unsatisfied FK constraint to directus_folders) if that default folder has been deleted earlier.

To Reproduce

  1. As an admin, create a folder through the Files module,
  2. Create a collection with an Image field, set the field's default upload folder to the one created above,
  3. Delete that folder through the Files module,
  4. Go to the Content module and try to add an Image to the collection.

Errors Shown

{
  "errors": [
    {
      "message": "insert into `directus_files` (`filename_download`, `folder`, `id`, `storage`, `title`, `type`, `uploaded_by`) values ('banner.jpg', '2b4d8424-8f18-4159-9eac-8fe878b2926a', '1f0eccfa-0a72-4c1f-b339-84bb2bc034bf', 'local', 'Banner', 'image/jpeg', '949f3a2f-be57-488b-8a2b-01b048ed42c7') returning `id` - SQLITE_ERROR: FOREIGN KEY constraint failed",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stack": "Error: insert into `directus_files` (`filename_download`, `folder`, `id`, `storage`, `title`, `type`, `uploaded_by`) values ('banner.jpg', '2b4d8424-8f18-4159-9eac-8fe878b2926a', '1f0eccfa-0a72-4c1f-b339-84bb2bc034bf', 'local', 'Banner', 'image/jpeg', '949f3a2f-be57-488b-8a2b-01b048ed42c7') returning `id` - SQLITE_ERROR: FOREIGN KEY constraint failed"
      }
    }
  ]
}

What version of Directus are you using?

9.11.1

What version of Node.js are you using?

16.15.0

What database are you using?

sqlite 3.38.5

What browser are you using?

Firefox

How are you deploying Directus?

running locally

rijkvanzanten commented 2 years ago

Duplicate of https://github.com/directus/directus/discussions/13083, a little bit of https://github.com/directus/directus/discussions/4368, and kinda https://github.com/directus/directus/issues/9507