Broken Mongoose Relationship Upon Setting Smart Field as Reference

Feature(s) impacted

Out-of-the-box one-to-many relationships based on a mongoose schema.

I have created a minimal viable repo to showcase the bug. Tip of master.

Observed behavior

  1. Create a lawyer without an office (office is not a required property).
  2. Set the office reference to name
  3. Open the previously created lawyer.
  4. Error.

Expected behavior

  1. No error.

Failure Logs

warning: [404] GET /forest/lawyers - 14ms

===== An exception was raised =====
GET /forest/lawyers?{
 timezone: Europe/Zurich,
 fields[lawyers]: _id,office__manyToOne,createdAt,firstName,lastName,updatedAt,
 fields[office__manyToOne]: name,
 page[number]: 1,
 page[size]: 15,
 sort: -_id
}

 Missing one of expected fields: '_id' 

Error: Missing one of expected fields: '_id'
    at Function.packId (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/@forestadmin/agent/src/utils/id.ts:25:13)
    at Object.beforeSerialize (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/@forestadmin/agent/src/services/serializer.ts:84:33)
    at JSONAPISerializer.serializeResource (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:565:22)
    at JSONAPISerializer.serializeRelationship (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:800:39)
    at /Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:693:20
    at Array.forEach (<anonymous>)
    at JSONAPISerializer.serializeRelationships (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:681:40)
    at JSONAPISerializer.serializeResource (/Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:572:27)
    at /Users/davidroegiers/Jurata/forest-admin-bug-reports/node_modules/json-api-serializer/lib/JSONAPISerializer.js:560:14
    at Array.map (<anonymous>)
===================================

Context

See repo.

Hello @David_Roegiers,

Thanks for your very detailed error case with the reproducing code. I’m creating a bug on our side and we’ll take a look as soon as possible.

I’ll keep you posted once it’ll be fixed.

1 Like