Datastore: `allocateId` should only accept an incomplete key
The current behavior is to "trim" the ID or name from the final path element before sending the key to the server: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java#L114
This means you can call allocateId on a key with a prepopulated ID, and the server will actuall allocate a completely different ID. This behavior is documented, but it seems surprising. Would be safer to either reject the allocateId call if the provided key contains an ID/name (or just let the server reject the call).
Reference: http://stackoverflow.com/questions/41878706/where-is-allocateids-in-the-google-cloud-datastore-java-library/41879429
This is a breaking change because it will fail in more cases than before.
I think there are two issues here.
The first one is that google-cloud-java library doesn’t have an allocateId function to reserve a user-specified ID (or a range of Ids), which is really what the stackoverflow user was looking for. My understanding is that the reference mentioned in that thread applies only to GAE. @eddavisson please correct me if I’m wrong.
The second issue is that the allocateId call in google-cloud-java can be called on a key and consequently overwrites the id. I agree we should not allow this in the client library(after all, the server call will reject a complete key).
We will fix the second issue.