Self relation is breaking the collection

Feature(s) impacted

CRUD operation on a collection

Observed behavior

When I click on my Workspace collection I get the following error.

Note:
It seem to be caused by a self reference relationship: a workspace can have a template (which is also a workspace object).
The problem disappeared when I did a migration to remove the relationship.
You can find here a dump of the sql schema of the table and my .forestadmin-schema.json

Expected behavior

I would expect to be able to display the elements of the collection and be able to edit an item.

Failure Logs

table name "Workspace" specified more than once

Error:
  at Query.run (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/dialects/postgres/query.js:76:25)
  at /Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/sequelize.js:641:28
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at PostgresQueryInterface.select (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)
  at Function.findAll (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/model.js:1816:21)
  at SequelizeCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-sequelize@1.0.0-beta.36_sequelize@6.21.3/node_modules/@forestadmin/datasource-sequelize/src/collection.ts:91:21)
  at ComputedCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.27/node_modules/@forestadmin/datasource-toolkit/src/decorators/computed/collection.ts:52:21)
  at RelationCollectionDecorator.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.27/node_modules/@forestadmin/datasource-toolkit/src/decorators/relation/collection.ts:37:21)
  at ComputedCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.27/node_modules/@forestadmin/datasource-toolkit/src/decorators/computed/collection.ts:52:21)
  at CollectionHookDecorator.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.27/node_modules/@forestadmin/datasource-toolkit/src/decorators/hook/collection.ts:79:21)

Context

  • Project name: Capsule
  • Team name: Founders
  • Environment name: production
  • Agent type & version: @forestadmin/agent 1.0.0-beta.47
  • Recent changes made on your end if any: problem as been present from install
1 Like

Hey @leonard_henriquez :wave:

Iā€™m not able to start a project as well using the CREATE TABLE you provided with a datasource-sql, so Iā€™ll file a ticket on our end.

Be sure we will ping you here once fixed :+1:

@jeffladiray Thank you for your quick response !
Do you have an ETA for the resolution? Is it possible to get the link to the bug report?

While you fix the problem, is there any way to fix this on my side?
Removing the constraint is not really an option because itā€™s need by my ORM (prisma) to create the relationship. But I guess there are other options:

  • Can I make Forest understand the relationship? (with something like this)
  • Or even overwrite the route? (but I canā€™t find the equivalent of this documention for the v2)

Sadly, the issue happens at the introspection level - before the agent even start. AFAIK (I wait for the tech-team to check whether or not thatā€™s true), there are no obvious way to workaround this issue at the moment.

We usually donā€™t give ETA on bug fixes, but be sure that it is already dispatched in the tech-team and that we are working on the fix as we speak.

1 Like

The same issue here:

The PR that should fix that issue is currently in review
Hopefully we can merge it today

Hi @anon39940173,
Thank you for your work ! :pray:
I saw that this PR was released as @forestadmin/agent@1.0.0-beta.54 and @forestadmin/datasource-sql@1.0.0-beta.47.

Unfortunately, I still get the same error:

table name "Workspace" specified more than once 

Error: 
    at Query.run (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/dialects/postgres/query.js:76:25)
    at /Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/sequelize.js:641:28
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at PostgresQueryInterface.select (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)
    at Function.findAll (/Users/leonard/code/capsule/node_modules/.pnpm/sequelize@6.21.3_pg@8.8.0/node_modules/sequelize/src/model.js:1816:21)
    at SequelizeCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-sequelize@1.0.0-beta.40_sequelize@6.21.3/node_modules/@forestadmin/datasource-sequelize/src/collection.ts:91:21)
    at ComputedCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.30/node_modules/@forestadmin/datasource-toolkit/src/decorators/computed/collection.ts:52:21)
    at RelationCollectionDecorator.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.30/node_modules/@forestadmin/datasource-toolkit/src/decorators/relation/collection.ts:37:21)
    at ComputedCollection.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.30/node_modules/@forestadmin/datasource-toolkit/src/decorators/computed/collection.ts:52:21)
    at CollectionHookDecorator.list (/Users/leonard/code/capsule/node_modules/.pnpm/@forestadmin+datasource-toolkit@1.0.0-beta.30/node_modules/@forestadmin/datasource-toolkit/src/decorators/hook/collection.ts:79:21)

Is there something I should change in my code?
Thank you in advance !!

Seriously? :sob::sob:

Can you send me information about the structure of the tables involved in the failing request?

A couple of create table statements that I can run on a local database would be best, but I would settle with anything that enables me to replicate the issue.

Wait no, there is still hope!

I just checked and the fix was NOT released.
I tagged my commit as ā€œrefactoringā€ so the build-bot did not release a new version

the fix should be live the next time we commit anything else

1 Like

We just triggered a release

Hopefully the following versions should get rid of the issue

  • @forestadmin/datasource-sql@1.0.0-beta.48
  • @forestadmin/agent@1.0.0-beta.55
1 Like

Itā€™s working :tada:
Thank you @anon39940173 !!