rezo-labs / directus-extension-schema-management-module

UI to easily share schema/role between Directus apps
GNU General Public License v3.0
141 stars 7 forks source link

Empty Schema Value Causes Schema Apply Failure #5

Open syoumans opened 1 year ago

syoumans commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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