ManyToOne relation on same Table make Forest crash on row selection

Feature(s) impacted

In Forest dashboard, at this url :
https://app.forestadmin.com/mycompany/Production/Operations/data/user/index
on the table row list, the click on a row should redirect to the detailed view of this row

Observed behavior

In Forest dashboard, at this url :
https://app.forestadmin.com/mycompany/Production/Operations/data/user/index
on the table row list, the click on a row in a table make application crash

Expected behavior

Display details of clicked row

Failure Logs

Dashboard error :
Cannot reach your data
Your server may be down or your database connection broken.
Please check your server logs for more information. If the error persists, please let us know .

browser error :
[forest] :feuillu::feuillu::feuillu: Unexpected error in details view:

Context

  • Project name: …
  • Team name: …
  • Environment name: …
  • Agent (forest package) name & version:
    @forestadmin/agent”: “^1.0.0-beta.41”,
    @forestadmin/datasource-sql”: “^1.0.0-beta.39”,
  • Database type: PosgreSql
  • Recent changes made on your end if any: add relation OneToMany on User table targeting the same table. Before this change, the dashboard did not crash

Hello @Ludovic_Lacuska,

Thanks for reaching out.

In order to help you out, could you please detail a little bit more:

  • In your case, one User has many other Users? What’s your use case?
  • Do you have any error in your agent console?
  • Could you share more details of the browser console error?

Thank you!

Hello,

Thanks for you fast reply.

This is how my users are linked :

class UserEntity {
  @ManyToOne(() => UserEntity, (user) => user.refferingUsers, {
      nullable: true,
    })
  @JoinColumn()
  refferedBy: UserEntity;

  @OneToMany(() => UserEntity, (user) => user.refferedBy)
  refferingUsers: UserEntity[];
}

I need to know if a user has been referred by another one (like sponsorship)

How can I access the agent console you’re talking about?

The browser error looks like this :

Message : Ember Data Request GET api-dot-MyCompany-production.oa.r.appspot.com/forest/user/3225 returned a 500\nPayload (application/json; charset=utf-8)\n[object Object]

Stack : Error: Ember Data Request GET  api-dot-MyCompany-production.oa.r.appspot.com/forest/user/3225 returned a 500\nPayload (application/json; charset=utf-8)\n[object Object]\n    at n.i (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:229557)\n    at new n (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:230315)\n    at b.handleResponse (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:236787)\n   
[[Prototype]]
: 
Error

And I have a 500 error on Get at this url :
api-dot-myCompany-production.oa.r.appspot.com/forest/user/3225?timezone=Europe%2FParis

Thanks !

Hello @Ludovic_Lacuska,

Can you please share with us the structure around this table User please? It’ll help us reproduce the issue. I don’t need all the tables nor all the columns : I just need a description of the ones involved in the issue.

In addition to that, I can see that you’re using a very old version of the packages : can you please update to the latest? The packages you’re using are beta versions. The recent versions are compatible with this one, so the jump won’t be difficult.

Thanks

Hello,

We tried to update our packages to this versions :
@forestadmin/agent”: “^1.28.1”,
@forestadmin/datasource-sql”: “^1.7.26”,

We had to install the package
@types/koa__router”: “^12.0.0”, in order to make the build works

We change the createAgent method from

const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    agentUrl: process.env.FOREST_AGENT_URL,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === "production",
    clientId: process.env.FOREST_CLIENT_ID,
  }).addDataSource(createSqlDataSource(process.env.DATABASE_URL));

To this

const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    forestServerUrl: process.env.FOREST_AGENT_URL,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === "production",
  }).addDataSource(createSqlDataSource(process.env.DATABASE_URL));

We don’t know how to use the FOREST_CLIENT_ID.

Deploying this we have an issue on Forest console.

Agent unreachable

https://app.forestadmin.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

On the app we use nest.js and we already have enable Cors

Concerning the User Entity the model is quite big but we had no issues before adding this relation on himself.

Thanks

Ok, this is another problem.

Can you please get the response from the agent to the OPTIONS request? I need the headers from this response.

You can remove the property forestServerUrl which won’t be useful in your case.

Hello,

Whe have 2 OPTIONS requests

The first request response header looks like this :

HTTP/1.1 204 No Content
Server: Cowboy
Connection: keep-alive
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
X-Dns-Prefetch-Control: off
Expect-Ct: max-age=0
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
Origin-Agent-Cluster: ?1
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: no-referrer
X-Xss-Protection: 0
Access-Control-Allow-Origin: https://app.forestadmin.com
Vary: Origin, Access-Control-Request-Headers
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Access-Control-Allow-Headers: authorization,content-type,forest-environment-id,forest-project-id,forest-rendering-id,forest-team-id
Access-Control-Max-Age: 86400
Access-Control-Expose-Headers: Content-Disposition
Content-Length: 0
Date: Thu, 14 Sep 2023 09:05:24 GMT
Via: 1.1 vegur

The request header :

OPTIONS /api/renderings/mycompany/Staging/Operations HTTP/1.1
Host: api.forestadmin.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization,content-type,forest-environment-id,forest-project-id,forest-rendering-id,forest-team-id
Referer: https://app.forestadmin.com/
Origin: https://app.forestadmin.com
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site

The second one response header :

HTTP/2 200 OK
content-type: application/json
vary: Accept-Encoding
x-powered-by: Express
content-encoding: gzip
x-cloud-trace-context: 354771bfdc2443edcee13e0d29dd78d8;o=1
date: Thu, 14 Sep 2023 09:05:24 GMT
server: Google Frontend
cache-control: private
content-length: 58
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
X-Firefox-Spdy: h2

The request header

OPTIONS /forest/authentication HTTP/2
Host: api-dot-mycompany.ew.r.appspot.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Referer: https://app.forestadmin.com/
Origin: https://app.forestadmin.com
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site

Thank you,

The first request is made to our servers and the response is correct.

The second request is made to your agent, and we can see that the response is not. We can see that Google Frontend’s servers instead of the agent.

I think that there is a problem with the deployment on your servers. The agent is not called by the server on the URL that is configured.

For info, if you open a browser and access to [your-agent-url]/forest it should answer a basic message such as

{"error":null,"message":"Agent is running"}

If you get an error from google instead, it means that something is misconfigured in the deployment.