Steps to reproduce:
- Install AdminBro with Express and Mongoose adapters
- Have resource with an array of objects (let's call them
Foo) as one of the properties. Those nested objects have to contain an array of objects (let's call them Bar) as one of their properties.
- Click "Create new" button (
new action).
- Fill the form with some data, including one
Foo object in the array.
- Fill the
Foo object with some data, including one Bar object in the array.
- Remove all
Bar objects from the array. (This is what triggers the bug. If the Bar array was empty and the user wouldn't touch it, the bug would not appear. Adding and removing items triggers the bug.)
- Save the record. AdminBro crashes the whole application. Not just the request, the whole app goes down.
Stack trace:
/home/user/Projects/some-project/node_modules/mongoose/lib/error/objectParameter.js:25
Error.captureStackTrace(this);
^
ObjectParameterError: Parameter "obj" to Document() must be an object, got
at new ObjectParameterError (/home/user/Projects/some-project/node_modules/mongoose/lib/error/objectParameter.js:25:11)
at EmbeddedDocument.Document (/home/user/Projects/some-project/node_modules/mongoose/lib/document.js:87:11)
at EmbeddedDocument [as constructor] (/home/user/Projects/some-project/node_modules/mongoose/lib/types/embedded.js:42:12)
at new EmbeddedDocument (/home/user/Projects/some-project/node_modules/mongoose/lib/schema/documentarray.js:116:17)
at cb (/home/user/Projects/some-project/node_modules/mongoose/lib/schema/documentarray.js:252:26)
at DocumentArrayPath.SchemaType.doValidate (/home/user/Projects/some-project/node_modules/mongoose/lib/schematype.js:1046:12)
at DocumentArrayPath.doValidate (/home/user/Projects/some-project/node_modules/mongoose/lib/schema/documentarray.js:201:37)
at /home/user/Projects/some-project/node_modules/mongoose/lib/document.js:2323:9
at process._tickCallback (internal/process/next_tick.js:61:11)
Example object Foo:
interface Foo {
name: string;
nested: Bar;
}
interface Foo {
title: string;
bugs: Baz; // this is the part triggering the bug
}
interface Baz {
anything: number;
}
More info:
The bug is being caused by two things: when we add and remove the object, request form/multipart made by the frontend will contain a field like this:
Notice that it has no value. If we haven't added and then removed objects from Foo then this field would not appear at all. That's the second reason for the bug - backend tries to parse that valueless field and Mongoose crashes.
Steps to reproduce:
Foo) as one of the properties. Those nested objects have to contain an array of objects (let's call themBar) as one of their properties.newaction).Fooobject in the array.Fooobject with some data, including oneBarobject in the array.Barobjects from the array. (This is what triggers the bug. If theBararray was empty and the user wouldn't touch it, the bug would not appear. Adding and removing items triggers the bug.)Stack trace:
Example object
Foo:More info:
The bug is being caused by two things: when we add and remove the object, request
form/multipartmade by the frontend will contain a field like this:Notice that it has no value. If we haven't added and then removed objects from
Foothen this field would not appear at all. That's the second reason for the bug - backend tries to parse that valueless field and Mongoose crashes.