When loading an Entity from the datastore and updating it, there is no way to exclude new attributes from being indexed, since the only public API for setting exclude_from_indexes is on the Entity constructor. To work around this, I am currently setting entity._exclude_from_indexes = (...) in my code, which is not a "public" API.
Example:
client = google.cloud.datastore.Client()
key = client.key('SomeEntityKey')
entity = google.cloud.datastore.Entity(key, exclude_from_indexes=('foo', 'bar'))
entity['foo'] = 'foo'
print 'entity.exclude_from_indexes:', entity.exclude_from_indexes
client.put(entity)
entity2 = client.get(entity.key)
print 'entity2.exclude_from_indexes:', entity2.exclude_from_indexes
entity2['bar'] = 'bar'
client.put(entity2)
Output:
entity.exclude_from_indexes: frozenset(['foo', 'bar'])
entity2.exclude_from_indexes: frozenset([u'foo'])
This is actually "expected" based on how the Datastore works, however, in the code sample above, there should be some way for me to put the entity back, without copying it into a brand new Entity.
Tested using:
- Mac OS X 10.11.6
- Python 2.7.10
- The following Google packages:
gapic-google-cloud-datastore-v1==0.15.3
google-auth==1.0.1
google-auth-httplib2==0.0.2
google-cloud-core==0.24.1
google-cloud-datastore==1.0.0
google-cloud-storage==1.1.1
google-gax==0.15.13
google-resumable-media==0.0.2
googleapis-common-protos==1.5.2
proto-google-cloud-datastore-v1==0.90.4
When loading an
Entityfrom the datastore and updating it, there is no way to exclude new attributes from being indexed, since the only public API for settingexclude_from_indexesis on theEntityconstructor. To work around this, I am currently settingentity._exclude_from_indexes = (...)in my code, which is not a "public" API.Example:
Output:
This is actually "expected" based on how the Datastore works, however, in the code sample above, there should be some way for me to put the entity back, without copying it into a brand new
Entity.Tested using: