This repository was archived by the owner on Apr 19, 2022. It is now read-only.
Make default property value functionality the same as in the original datastore NDB.#11
Open
rotemvil1 wants to merge 1 commit intoberlincode:masterfrom
Open
Make default property value functionality the same as in the original datastore NDB.#11rotemvil1 wants to merge 1 commit intoberlincode:masterfrom
rotemvil1 wants to merge 1 commit intoberlincode:masterfrom
Conversation
Owner
|
Hello and thank you for your report. I totally agree with you that the behavior between python2 and python3.7 should be as close as possible. The line you are changing should imho work exactly the same on both python2 and python3.7. I've tried to reproduce your problem without success. On python2, python3.6 and python3.7 a non-set property with a default value is NOT stored! If you load the entity from the datastore ndb-orm shows you the default value from your model. This only works (of course) if you load your model class before fetching the entity. Maybe this might be the problem? |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The original NDB behavior when using default parameter is passing the default value inside datastore even when initiating a Model without the relevant. Currently, that doesn't happen. The entity is being saved without the default value which means that you can't query on it and worst than that, if you'll change the default value in the application level it'll affect on retro actively inserted queries.
Python 2.7 NDB example code:
In python 2.7 this entity will be saved with myCounter=20 in datastore while in python 3.7 this entity will be saved as an empty (containing only a key, missing myCounter aka missing all default properties that wasn't set explicitly in the Model init).
Python 37 NDB example code:
Can be checked easily with this code:
client.get(client.key('DefaultTest', 123))['myCounter']Which will get an exception in the Python 3.7 DS while in the 2.7 DS it'll get the correct value.