endpoints-proto-datastore

Simple PUT not modifying the model


The route is shown below and I can confirm the request is hitting the route, however, the model parameter is the currently saved model, when I'd expect it to be the model with updated properties.

@Page.method(request_fields=('id',),
             path='page/{id}', http_method='PUT', name='page.udpate')
def PageUpdate(self, model):
    if not model.from_datastore:
        raise endpoints.NotFoundException('MyModel not found.')
        model.put()
    return model

Solution

  • The request_fields field specifies what comes in the request, so you'll want to include a lot more. The _message_fields_schema property (discussed in simple_get example) is best to use.

    class Page(EndpointsModel):
    
      _message_fields_schema = ('id', ... other properties)
    

    and then just let the default be used:

    @Page.method(path='page/{id}', http_method='PUT', name='page.update')
    def PageUpdate(self, page):
        if not page.from_datastore:
            raise endpoints.NotFoundException('Page not found.')
            page.put()
        return page
    

    NOTE: I also changed the spelling of 'page.udpate' and the text in the error message.