-
Notifications
You must be signed in to change notification settings - Fork 362
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
Do not apply default values on data from database [3.x] #1705
Conversation
The failure seems unrelated, see https://cis-jenkins.swg-devops.com/job/ds/job/loopback-connector-mongodb%7Emaster/35/console
This is a valid failure. Because the new tests don't run autoupdate/automigrate, the database schema is not matching model schema. I'll investigate. |
In 6e7aee4, I added However, there are still few failures that look relevant to me. @jannyHou could you please help me to investigate the Cloudant failure? Cloudant
The other two test failures reported by Cloudant seem unrelated, they are reported by CouchDB connector too. @raymondfeng could you please help me with MSSQL? It looks like a bug in the mssql
Other test failures seem unrelated: dashdb Seems unrelated:
Same error for "db2" . kv-extreme-scale Cannot connect to the testing database :( mongodb@3.x Fails in Similarly for mongodb@master. rest
|
Sure I am looking a the Cloudant failure. Update: The first commit in loopbackio/loopback-connector-couchdb2#59 fixes the first test case. Still investigating the second one. |
Apparently, there are other tests (or our setup script) using Anyhow, I managed to fix the problem by renaming my test model from |
I managed to fix this problem with a small tweak in Cloudant's test suite, see loopbackio/loopback-connector-cloudant#202 |
I consider this pull request as done, I'll clean up the git history before landing. @jannyHou @raymondfeng please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, except for the choice of the data type to test with.
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good now.
f91aa80
to
a39a2c7
Compare
Actually, it turns out my original test assertions were correct. When the connector returns property value null, we don't consider it to be undefined and thus the default value is not applied. How confusing! I have reverted f498c26 and updated the comments in the tests to make this more clear. |
Before this change, when a property was configured with a default value at LoopBack side and the database was returned a record with a missing value for such property, then we would supply use the configured default. This behavior is problematic for reasons explained in #1692. In this commit, we are introducing a new model-level setting called `applyDefaultsOnReads`, which is enabled by default for backwards compatibility. When this setting is set to `false`, operations like `find` and `findOrCreate` will NOT apply default property values on data returned by the database (connector). Please note that most of the other CRUD methods did not apply default values on database data as long as the connector provided native implementation of the operation, that aspect is not changing. Also note that default values are applied only on properties with `undefined` values. The value `null` does not trigger application of default values. This is important because SQL connectors return `null` for properties with no value set.
a39a2c7
to
fd03302
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 LGTM
Before this change, when a property was configured with a default value at LoopBack side and the database was returned a record with a missing value for such property, then we would supply use the configured default.
This behavior is problematic for reasons explained in #1692.
In this patch, we are introducing a new model-level setting called
applyDefaultsOnReads
, which is enabled by default for backwards compatibility.When this setting is set to
false
, operations likefind
andfindOrCreate
will NOT apply default property values on data returned by the database (connector).Please note that most of the other CRUD methods did not apply default values on database data as long as the connector provided native implementation of the operation, that aspect is not changing.
Also note that default values are applied only on properties with
undefined
values. The valuenull
does not trigger application of default values. This is important because SQL connectors returnnull
for properties with no value set.Related issues
This is a back-port of #1704. Compared to #1704 (master/4.x), we are preserving backwards compatibility by introducing a new feature flag.
See also #1692.
/cc @sharathmuthu6 @snarjuna
Checklist
guide