You're being misled by the ndb in-context cache:
When an NDB function writes to the Datastore, it also writes to the in-context cache. When an NDB function reads an entity, it checks the in-context cache first.
Since you're doing a direct .get()
, rather than a query, ndb will use the in-context cache and return the same object. It doesn't get a new instance from the datastore, so you will see that object's local modifications. You can verify this with:
self.assertTrue(record is record3)
Alternatively, use a query, or set the context specifically to disable the cache as explained at the link above.