Skip to content

Regression: dynamic coercion of Model will clobber property values on update #1806

@fabien

Description

@fabien

I finally went through a full update cycle with my apps, and in updating from 2.18.0 to 2.23.0 I discovered the following undesired (and BC breaking) behavior:

With a property that has some default value (either static or a fn/dynamic value):

"properties": {
  "foo": {
    "type": "string",
    "default": "bar"
  }
}
// create receives a new instance, with defaults filled in
// which we'll overwrite by our new data
this.request.post('/api/things')
  .send({ foo: 'other' }).end(function(err, res) {
  res.body.foo.should.equal('other');
  // id: 1234567890
  next();
});

// updateAttributes now receives a new instance, with defaults filled in
// but this time, we don't have any value for 'foo' set explicitly
// and thus the default will be used for the update(!)
this.request.put('/api/things/1234567890')
  .send({ biz: 'baz' }).end(function(err, res) {
  res.body.biz.should.equal('baz');
  res.body.foo.should.equal('other'); // Fail: overwritten by default: 'bar'
  next();
});

I think it's related to this commit: strongloop/strong-remoting@34b0665

/cc @bajtos @ritch


See #1806 (comment) for the proposed solution.

  • Implement support for arg.model in loopback-swagger
  • Rework remoting metadata in LoopBack, use { type: 'object', model: modelName } everywhere. Make sure to add unit-tests reproducing the problem and then demonstrating that the problem is fixed.

The last item from the proposal is tracked by a standalone issue: #2313

Fix swagger metadata for updateAttributes and friends to correctly indicate all properties are optional. Check other schema parts like "default" values, we may need to remove them too.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions