15

in my app i need to remove a few of my models properties.
i checked out this link but the first issue is that the properties are on a polymodel and there is no way im going to switch to an expando for the time to remove the properties, im not even shure what could happen if i change a polymodel to an expando.

so how do i remove properties from existing entities?

i was thinking to set all StringProperty to None and then remove these from the model schema and redeploy. one of those properties is a BooleanProperty, i can't set this one to None right?! or an ndb.PickleProperty... how should i remove that?

does anybody know how to get this done properly?

aschmid00
  • 7,038
  • 2
  • 47
  • 66

1 Answers1

41

If you want to update all your entities the recommended approach is a map/reduce job that reads and rewrites all entities; however it may not be worth it, depending on how much data you have -- the map/reduce isn't free either.

Also be sure you test the map/reduce job on a small subset of the data. It is remarkably subtle to truly remove a property from an entity, even if it's not in the model class any more! The best approach may be:

if 'propname' in ent._properties:
  del ent._properties['propname']
  ent.put()
Guido van Rossum
  • 16,690
  • 3
  • 46
  • 49
  • thx guido! yes i have to evaluate if its actually worth... i have around 100k entities so it might be even ok to remove the property from the schema. what does happen if i remove the property, redeploy and then reput the entity? would this discard those properties or would i still need to remove them from the object? – aschmid00 Oct 03 '12 at 15:38
  • 6
    Reputting after the schema change does not remove the property value. (This is a deliberate feature intended to maximize interoperability between two versions of an app.) – Guido van Rossum Oct 04 '12 at 02:31
  • If I am interested to just setting the property to None because I will be repopulating these attributes, what are my options? – xjq233p_1 Jul 24 '14 at 03:01
  • There is a subtle gotcha in the code snippet above: `_properties` is not necessarily an attribute of the entity instance, it is also an attribute of the model class. Thus the code above may mutate the class, leading to weird bugs and inconsistencies. The fix is to call `ent._clone_properties()` before the `del` statement, which takes care of cloning the class properties to the instance. – gsakkis Dec 16 '15 at 09:31
  • I did the above but the column is still visible in my cloud console table view though values are not there. – Punita Ojha Apr 27 '21 at 10:59