strapi-plugin-config-sync
strapi-plugin-config-sync copied to clipboard
Undefined attribute level operator <col> when trying to export relations
Bug report
Describe the bug
I have this in customTypes
{
configName: 'foos',
queryString: 'api::foo.foo',
uid: 'type',
relations: [
{
queryString: 'api::bar.bar',
relationName: 'bars',
parentName: 'foo',
relationSortFields: ['name'],
}
],
},
and when I visit the tool page in Settings, I get an error.
I tried to debug it a lot but haven't gotten anywhere with the root cause. I'd be happy to PR a fix (if it's a bug) when pointed in the right direction.
![Screenshot 2022-09-06 at 13 00 18](https://user-images.githubusercontent.com/2510597/188574172-adb910be-b52c-4e10-9950-91533d737970.png)
Steps to reproduce the behavior
- Set the customTypes as shown above (including relations)
- Click on Settings page
- Click on Tool page
- See error
Expected behavior
Similar to how exporting relations work for users-permissions plugin, it should work for any model.
Hi @salmanm,
Thanks for opening this issue.
Let me start by saying the relation syncing is an undocumented and unstable feature that only works if you take the right precautions. Though having said that, after seeing your error logging, I can't pin-point the exact source of your issue.
If you are willing to share the schema.json
files of both the parent and the child models I could take a look to see if I can spot the problem.
PS: Did you get any stacktrace to where exactly the issue originated from in the plugins code?
Thanks @boazpoolman, I've put together an example repo here.
If you run it as is, and go to the tool page you'll get an error just loading it.
![image](https://user-images.githubusercontent.com/2510597/188874408-fd78ed17-d514-4ed0-a575-a276b0e8cc67.png)
and this is the stacktrace (I increased the limit to capture all of it)
[2022-09-07 17:38:12.994] error: Undefined attribute level operator name
Error: Undefined attribute level operator name
at processAttributeWhere (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/helpers/where.js:83:13)
at processWhere (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/helpers/where.js:145:45)
at /Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/helpers/where.js:105:31
at Array.map (<anonymous>)
at Object.processWhere (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/helpers/where.js:105:18)
at Object.processState (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/query-builder.js:248:29)
at Object.getKnexQuery (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/query-builder.js:285:12)
at Object.execute (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/query/query-builder.js:388:25)
at Object.count (/Users/Salman/Repos/export-relation/node_modules/@strapi/database/lib/entity-manager.js:143:10)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async noLimit (/Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/utils/index.js:82:27)
at async /Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/config/type.js:198:27
at async Promise.all (index 0)
at async /Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/config/type.js:197:7
at async Promise.all (index 0)
at async ConfigType.getAllFromDatabase (/Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/config/type.js:183:5)
at async /Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/services/main.js:152:24
at async Promise.all (index 4)
at async getConfigs (/Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/services/main.js:147:7)
at async Object.getFormattedDiff (/Users/Salman/Repos/export-relation/node_modules/strapi-plugin-config-sync/server/services/main.js:275:28)
at async returnBodyMiddleware (/Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
at async policiesMiddleware (/Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
at async serve (/Users/Salman/Repos/export-relation/node_modules/koa-static/index.js:59:5)
at async returnBodyMiddleware (/Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
at async policiesMiddleware (/Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
at async /Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/middlewares/body.js:58:9
at async /Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/middlewares/logger.js:25:5
at async /Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
at async cors (/Users/Salman/Repos/export-relation/node_modules/@koa/cors/index.js:56:32)
at async /Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
at async session (/Users/Salman/Repos/export-relation/node_modules/koa-session/index.js:41:7)
at async /Users/Salman/Repos/export-relation/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5
I've pushed the config that causes this bug in the last commit chore: add config that causes bug so if you just revert that change, everything will work fine.
This should provide you with enough details to investigate the issue but let me know if I can help in any way.
Hi @salmanm,
I haven't tried starting the example instance you provided just yet.
Though looking at the code I did see that the bar
schema does not have a manyToOne relation back to foo
.
This related CT must have a field that holds the parent. Otherwise the feature doesn't work. See how that looks in the permission CT of the native users-permissions plugin: https://github.com/strapi/strapi/blob/main/packages/plugins/users-permissions/server/content-types/permission/index.js
I've tried adding manyToOne
already but it doesn't make a difference.
Please could you try out my repo and post any pointers that'd help me fix the issue
Update: After adding manyToOne
it still fails if any row does not have a relation populated. and when all rows have relations populated it doesn't fail but still doesn't export relations.
Also, I feel there should not be the need to define the reverse relation and we should still be able to export. There may be cases where it doesn't make sense to see all parent items in a child entity.
Here's a PR that fixes my issue https://github.com/boazpoolman/strapi-plugin-config-sync/pull/70. Thoughts?
I'm looking to see if there are any side-effects of this change.
Update: PR 70 works perfect for my case.
Thanks for putting up a PR. I will take a look and review as soon as I have the time 🙂
Hi @salmanm,
Just wanted to thank you for putting up a PR to fix this issue and at the same time appologize as I have not been able to review your work.
I noticed you closed the PR. Did that have a reason other than me being unresponsive? I'm not in a position currently to review the work, but as soon as I am I definitely want to get back to you on this.
That's all for now. Hope you made the plugin work for you're usecase :)
I realized that my PR solved one issue but probably created another one and I didn't have enough time to resolve that. I was hoping to get some direction on how to go about it.
No I couldn't make the plugin work for my use case. Although it's great for config sync as it claims to do, but for custom content types it has some things to iron out.
Basically I was looking for something to allow me to auto import seed data from a JSON file, and keep it in sync.
Got it. Thanks for your feedback 🙂
EDIT: I've forked you're example repo if I were to continue on this issue. https://github.com/boazpoolman/export-relation
I'm disappointed to see you say that the "relation syncing is an undocumented and unstable feature", given that is part of the documentation and nowhere does it say that it is unstable.
I too am getting this error when trying to include a relations array in a customType object.
If the relations feature is not supported, please remove it from your documentation or mark it as unstable.
The comment you quote is from a long time ago.
Since then major changes have been made to the relations feature, including the contribution of PhilippPaoli which allows for components syncing.
I wouldn't call this feature unstable anymore, though I agree that this issue needs to be fixed. I would accept a PR with a disclaimer in the README, linking to this issue.
Though I would much rather see a PR to fix this issue a a whole.