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

Empty Schema Value Causes Schema Apply Failure #5

Open
syoumans opened this issue Jul 18, 2023 · 2 comments
Open

Empty Schema Value Causes Schema Apply Failure #5

syoumans opened this issue Jul 18, 2023 · 2 comments

Comments

@syoumans
Copy link

Using Directus 9.21.* When exporting the schema of a collection, the schema value is empty, which seems to cause relationships to fail. When I add the name of the collection to the schema value in the JSON, I can apply the schema without errors.

Example Exported Collection
"collections": [ { "collection": "test_collection_2", "meta": { "collection": "test_collection_2", "icon": null, "note": null, "display_template": null, "hidden": false, "singleton": false, "translations": null, "archive_field": "status", "archive_app_filter": true, "archive_value": "archived", "unarchive_value": "draft", "sort_field": null, "accountability": "all", "color": null, "item_duplication_fields": null, "sort": 68, "group": null, "collapse": "open" }, "schema": {} } removed fields and relations ]

When I use the above with npx directus schema apply ./file.json I get the following error:

ERROR: Failed to create relation "test_collection_2.image"
ERROR: Invalid payload. Collection "test_collection_2" doesn't exist.
    err: {
      "type": "",
      "message": "Invalid payload. Collection \"test_collection_2\" doesn't exist.",
      "stack":
          DirectusError: Invalid payload. Collection "test_collection_2" doesn't exist.
              at RelationsService.createOne (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/services/relations.js:119:19)
              at file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/utils/apply-diff.js:206:44
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      "name": "DirectusError",
      "extensions": {
        "reason": "Collection \"test_collection_2\" doesn't exist"
      },
      "code": "INVALID_PAYLOAD",
      "status": 400
    }

After changing schema to be:
"schema": {"name": "test_collection_2"}
The apply works.

Maybe this is more of a Directus issue with the data coming out of the API? Thank you for considering this.

@duydvu
Copy link
Contributor

duydvu commented Jul 22, 2023

Hi @syoumans
I followed the guide in the documentation to set the schema field to an empty object when exporting.
Screenshot 2023-07-22 at 09 22 14

So with "schema": {}, it should not cause any errors. I also tested on 9.21.0 and no bugs have been detected so far.
Without much context (i.e. where does the image field come from), I can't be sure about the root cause.

If it still troubles you, could you give me more info about your schema in a reproducible way?

@syoumans
Copy link
Author

Interesting. Thank you for checking! We're upgrading to 10.x now; I'll report back shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants