Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upsert doesn't catch errors #1553

Open
ghost opened this issue Jul 30, 2015 · 6 comments
Open

upsert doesn't catch errors #1553

ghost opened this issue Jul 30, 2015 · 6 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Jul 30, 2015

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.

@ghost ghost changed the title upsert doen't catch errors upsert doesn't catch errors Jul 30, 2015
@ritch
Copy link
Member

ritch commented Aug 6, 2015

"options": {
  "validateUpsert": true
}

Do you have this in your model settings?

@ghost
Copy link
Author

ghost commented Aug 7, 2015

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.

@ritch
Copy link
Member

ritch commented Aug 7, 2015

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.

@viljami
Copy link

viljami commented Dec 16, 2015

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.

@elropero
Copy link

elropero commented Aug 5, 2016

Just tripped into this as well. In my case trying to upsert when violating a unique key constraint is failing silently.

@bajtos bajtos removed the major label Nov 12, 2019
@stale
Copy link

stale bot commented Jul 21, 2021

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.

@stale stale bot added the stale label Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants