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

Undefined attribute level operator <col> when trying to export relations #69

Open
salmanm opened this issue Sep 6, 2022 · 12 comments
Open
Labels
bug Something isn't working Needs investigation Further information is requested

Comments

@salmanm
Copy link

salmanm commented Sep 6, 2022

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

Steps to reproduce the behavior

  1. Set the customTypes as shown above (including relations)
  2. Click on Settings page
  3. Click on Tool page
  4. See error

Expected behavior

Similar to how exporting relations work for users-permissions plugin, it should work for any model.

@boazpoolman
Copy link
Member

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?

@boazpoolman boazpoolman added the Needs investigation Further information is requested label Sep 6, 2022
@salmanm
Copy link
Author

salmanm commented Sep 7, 2022

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

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.

@boazpoolman
Copy link
Member

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

@salmanm
Copy link
Author

salmanm commented Sep 11, 2022

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

@salmanm
Copy link
Author

salmanm commented Sep 12, 2022

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.

@salmanm
Copy link
Author

salmanm commented Sep 12, 2022

Here's a PR that fixes my issue #70. Thoughts?

I'm looking to see if there are any side-effects of this change.

Update: PR 70 works perfect for my case.

@boazpoolman
Copy link
Member

Thanks for putting up a PR.
I will take a look and review as soon as I have the time 🙂

@boazpoolman boazpoolman added the bug Something isn't working label Sep 23, 2022
@boazpoolman
Copy link
Member

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 :)

@salmanm
Copy link
Author

salmanm commented Dec 1, 2022

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.

@boazpoolman
Copy link
Member

boazpoolman commented Dec 1, 2022

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

@briannaneiderman
Copy link

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.

@boazpoolman
Copy link
Member

boazpoolman commented Apr 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs investigation Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants