When using the agent and the Mongoose datasource with a collection with fields that have a nested object schema, the Forestadmin UI crashes when visiting that collection.
We are encountering this error on all Mongoose models defined with a schema like this one:
const cardSchema = new Schema(
{
game: {
type: Schema.Types.ObjectId,
ref: "Game",
required: true,
index: true,
},
gameSlug: { type: String, required: true, index: true },
slug: { type: String, required: true, index: true },
name: { type: String },
test: {
a: Number,
b: Number,
},
},
{ strict: false, strictQuery: false },
);
Here, it is the test
field that is causing the error, making the entire UI unusable.
This part of the client-side code running in the browser throws an exception:
get filterActivated() {
const e = this.collection?.rendering?.environment
, t = !this.collection?.isSmart && this.isVirtual
, i = !!e && this.lianaFeatures.isFeatureCompatible(f.FeaturesEnum.FilterSmartField, e);
return this.isFilterAvailableForType && this.isFilterDisplayed && this.canFilter && (!this.capabilities || this.capabilities && this.capabilities.operators.length > 0) && (!t || i)
}
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘length’)
This happens because the value of this.capabilities.operators
is undefined
.
I am not sure if this issue is because of the schema introspection and what is returned to the forestadmin UI, or if it’s directly an issue on the UI side.
Using latest versions of the agent and mongoose datasource
Cross-reference, this issue here : Nested Mongoose fields make the Forestadmin UI crash? · Issue #1271 · ForestAdmin/agent-nodejs · GitHub