Search code examples
google-app-engineapp-engine-ndbgoogle-app-engine-python

In Google App Engine's Python DataStore model, is the result of get_by_key_name(<list_input>) in the same order as the input?


The following code gets a list of entities in bulk by their key names:

key_names = [a, b, c, d, e]
result = models.SomeModel.get_by_key_name(key_names)

The question is:

Can we safely assume that the order of the entities in the returned list is always the same as the order of keys in the input list (key_names)?


Solution

  • From Class Methods (emphasis mine):

    Model.get_by_key_name (key_names, parent=None)

    ...

    If key_names consists of a single key name, this method returns the model instance associated with the name if the name exists in the Datastore, otherwise None. If key_names is a list, the return value is a corresponding list of model instances, with None values where no entity exists for a given key name.

    I considered that a confirmation and I did make that assumption in my code At least so far I didn't encounter any error or other hint/indication that the assumption would somehow be incorrect.