upsert doesn't catch errors
The upsert() method doesn't catch errors (duplicate key, foreign key, ...). The callback doesn't get error object, and gets the "updated" model instance. This happens in both cases (update or insert). I'm using MySQL.
"options": {
"validateUpsert": true
}
Do you have this in your model settings?
Thanks. Yes, I have it. The property validateUpsert ensure that upsert() returns an error when validation fails (http://docs.strongloop.com/display/public/LB/Model+definition+JSON+file). What I mean the errors (duplicate key, foreign key, ...) are fired from the database operation, after the model validation.
Ah... well validation can include validating uniqueness.
As far as errors thrown from the database, @raymondfeng do you have any thoughts? Missing an error thrown from the driver sounds like a large issue.
Upsert fails silently when float number is sent to column defined as number with postgresql. I hope this example shows it. I have Strongloop model definition json file with column:
"score": {
"type": "number"
}
And I send PUT request with url /model (or /model/:id) containing body:
{
"id":"1",
"score": 123.123
}
The response will have status code 200 and the response body will have the updated score, but A GET request shows that the model got never updated.
I can fix this by updating my model definition:
"score": {
"type": "number",
"postgresql": {
"columnName": "score",
"dataType": "numeric",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 5,
"nullable": "NO"
}
}
Only catching and communicating this to my 3rd party users is tricky because they will assume everything worked fine.
Just tripped into this as well. In my case trying to upsert when violating a unique key constraint is failing silently.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.