How to find out whether default value is used for Datastore ndb property?

110 Views Asked by At

Let's say we have a model like this:

class UserConfig(ndb.Model):
    name = ndb.StringProperty()
    email_subscriber = ndb.BooleanProperty(default=True)

Let's assume email_subscriber was set to default True by mistake and we want to fix that mistake and use default=False instead. I tried changing the value to default=False and that works fine for users created after that code is deployed, but that doesn't fix the problem for existing users.

Is there a way (e.g. some internal property which isn't documented in Datastore documentation), which would provide info whether given prop value was set explicitly by user or using the provided default.

I can write an upgrade which would set email_subscriber=False for all users, but I'm afraid some users might have intentionally checked this property in the app and wouldn't like to break their experience.

tl;dr: How can I determine if value in ndb object was set using the default for that property or was provided explicitly.

1

There are 1 best solutions below

0
Jim Morrison On

There is no way to know this. Once a value is set in the database there is no way to know which part of your code (ndb runs in your code from the database perspective) set the value.