The 404
is expected. The "magic" of the id
property is that it calls UpdateFromKey.
This method tries to set an ndb.Key
on the entity based on the request and then attempts to retrieve the entity stored with that key. If the entity exists, the values from the datastore are copied over to the entity parsed from the request and then the _from_datastore
property is set to True
.
By using request_fields=('title',)
, you have a simple data property rather than an EndpointsAliasProperty
and so only the values are set. As a result, _from_datastore
never gets set and your check
if not recipe.from_datastore:
raise endpoints.NotFoundException('Recipe not found.')
throws an endpoints.NotFoundException
as expected.