Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

clearRelatedCache causes crash when model contains file collection #54

Description

@josias-milk

When clearRelatedCache is enabled and a model contains a field which is a file collection, the following crash occurs:

TypeError: Cannot read property 'kind' of undefined
      at /Users/foo/myproject/node_modules/strapi-middleware-cache/lib/index.js:195:51
      at /Users/foo/myproject/node_modules/lodash/lodash.js:4967:15
      at baseForOwn (/Users/foo/myproject/node_modules/lodash/lodash.js:3032:24)
      at /Users/foo/myproject/node_modules/lodash/lodash.js:4936:18
      at Function.forEach (/Users/foo/myproject/node_modules/lodash/lodash.js:9410:14)
      at clearCache (/Users/foo/myproject/node_modules/strapi-middleware-cache/lib/index.js:194:13)
      at async /Users/foo/myproject/node_modules/strapi-middleware-cache/lib/index.js:248:9
      at async bustAdmin (/Users/foo/myproject/node_modules/strapi-middleware-cache/lib/index.js:318:11)
      at async /Users/foo/myproject/node_modules/strapi/lib/middlewares/responses/index.js:9:9
      at async cors (/Users/foo/myproject/node_modules/@koa/cors/index.js:95:16)
      at async /Users/foo/myproject/node_modules/strapi/lib/middlewares/logger/index.js:56:11
      at async /Users/foo/myproject/node_modules/strapi/lib/middlewares/responseTime/index.js:17:9
      at async /Users/foo/myproject/node_modules/strapi/lib/services/metrics/middleware.js:29:5
      at async /Users/foo/myproject/node_modules/strapi/lib/Strapi.js:325:9

In my project I have a field called imageGallery which looks like this:

    "imageGallery": {
      "collection": "file",
      "via": "related",
      "allowedTypes": [
        "images"
      ],
      "plugin": "upload",
      "required": false,
      "pluginOptions": {}
    }

I think the problem is in the getRelatedModels function, line 102ff:

    if (attr.collection) {
      relatedModels[attr.collection] = models[attr.collection];
    } else if (attr.model && attr.model !== 'file') {
      relatedModels[attr.model] = models[attr.model];
    }

In the first case, when attr.collection is true, I think it should also check that the collection != 'file'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions