Missing one of expected fields ( typically on a relationship )

Feature(s) impacted

Automatic detection of relationships in schema.

Observed behavior

I’ve gone ahead and installed the ForestAdmin backend and successfully deployed it as well as ran it locally. However when I try to access some of the pages I get a 500 error. On the backend its complaining that I’m missing one of the expected fields, this seems to always be related to a relationship. The biggest difference between now and other times I’ve used ForestAdmin is that I’m not leveraging and ORM, but rather the SQL data source. Its seems to be a missmatch between what the schema is and what the GET request is asking for. I see this issue with several different types of relationships.

Does anyone know there is some convention ForestAdmin requires your database to follow for this to work? Anything I can do setting wise or as a default rule to the data source to fix this? Changing the schema or manually adding the relationships ( like an ORM ) is not really an option.

Expected behavior

Expect it just to work.

  • Project name: Unified Vision
  • Team name: none
  • Environment name: Development/Staging
  • Agent technology: NodeJS
  • Agent (forest package) name & version: @forestadmin/datasource-sql@1.16.3
  • Database type: PostgreSQL
  • Recent changes made on your end if any: None! Never got this working

Hello @Rein, welcome to the community

Your agent console logs should have details and a stack trace concerning the error that causes the 500 on the frontend side.
Can you please share those to help us investigate further ?
thanks :pray:

Yepp!

See following, I’ve a anonymised the data, but structure is identical! field_e is the relation, matches table name.

[1] ===== An exception was raised =====
[1] GET /endpoint?{
[1]  timezone: America/New_York,
[1]  fields[field_a]: field_a_id,
[1]  fields[field_b]: field_b_id,
[1]  fields[field_c_enum]: field_c,
[1]  fields[field_d]: field_d_id,
[1]  fields[field_e]: field_e_id,
[1]  page[number]: 1,
[1]  page[size]: 15
[1] }
[1]
[1]  Missing one of expected fields: 'field_e_id'
[1]
[1] Error: Missing one of expected fields: 'field_e_id'
[1]     at IdUtils.packId (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/@forestadmin+agent@1.56.1/node_modules/@forestadmin/agent/dist/utils/id.js:14:19)
[1]     at Object.beforeSerialize (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/@forestadmin+agent@1.56.1/node_modules/@forestadmin/agent/dist/services/serializer.js:61:46)
[1]     at JSONAPISerializer.serializeResource (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:565:22)
[1]     at JSONAPISerializer.serializeRelationship (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:800:39)
[1]     at /Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:693:20
[1]     at Array.forEach (<anonymous>)
[1]     at JSONAPISerializer.serializeRelationships (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:681:40)
[1]     at JSONAPISerializer.serializeResource (/Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:572:27)
[1]     at /Users/rein/Engineering/uv-admin/node_modules/.pnpm/json-api-serializer@2.6.6/node_modules/json-api-serializer/lib/JSONAPISerializer.js:560:14
[1]     at Array.map (<anonymous>)

Hello @Rein,
Thanks for the details.
I tried reproducing your issue with a similar schema, but to no avail.

to answer your specific question

Does anyone know there is some convention ForestAdmin requires your database to follow for this to work? Anything I can do setting wise or as a default rule to the data source to fix this?

No there is not really. It should work out of the box with any standard recent postgreSQL instance

Some more details that might help us investigate:

  • I assume that the problematic relationships are declared in the postgre schema, and not in code your forest agent, is that correct ?
  • Do you have collections with relationships that are displayed correctly ?
  • If so do you have anything different in the collections that you cannot access, for instance in the way they are declared in the pg schema ? Or they are using pg extensions ? or use non-standard data types ?
  • If you make changes to your development database schema, do you see those reflected in the forestadmin-schema.json file after your agent has restarted ?
  • Are you able to successfully perform changes to the layout on the app ? Like hiding a column for instance ? And are those saved correctly upon page reload ?
  • If the above is ok, could you try hiding the columns that cause an issue, and let me know if this changes anything ?
  • Would you be able to provide a minimal reproducible example, in the form of a simple postgre database schema with a couple tables, one of causing the same error that you see in your dev environment.

Thanks :pray:

This is the error I get in the UI, so I can’t edit columns:

Thanks for the details answers,
Unfortunately, this does not really pinpoint anything that could lead to the behaviour that you are experiencing. Did you manage to get a reproducible example together ? :pray: