@EndpointsAliasProperty и @Model.query_method вызывают BadRequestError(Ключевой элемент пути не должен быть неполным:...)

Привет, сейчас я занимаюсь разработкой API для сервера приложений с помощью Google ProtoRPC и конечных точек. Я использую endpoints-proto-datastore библиотека.

Так странные вещи случаются здесь, вот EndpointsModel учебный класс

class AssetData(EndpointsModel):
    type = msgprop.EnumProperty(AssetType, indexed=True)

    def auth_id_set(self, value):
        if ApplicationID.get_by_id(value) is None:
            raise endpoints.UnauthorizedException('no auth_id')

        self._auth_id = value

    @EndpointsAliasProperty(required=True, setter=auth_id_set, property_type=messages.IntegerField)
    def auth_id(self):
        return self._auth_id

    def app_id_set(self, value):
        if ApplicationID.query(ApplicationID.app_id == value).get() is None:
            raise endpoints.UnauthorizedException('wrong app_id')

        self._app_id = value

        if self.check_auth_app_id_pair(self.auth_id, value):
            self._app_id = value
        else:
            raise endpoints.BadRequestException('auth_id and app_id mismatch')

    @EndpointsAliasProperty(required=True, setter=app_id_set)
    def app_id(self):
        return self._app_id

    @staticmethod
    def check_auth_app_id_pair(authen_id, applic_id):
        dat = ApplicationID.get_by_id(authen_id)
        if dat.app_id != applic_id:
            return False
        else:
            return True

и это класс API

@endpoints.api(...)
class AssetDatabaseAPI(remote.Service):

    @AssetData.query_method(query_fields=('limit', 'order', 'pageToken', 'type', 'auth_id', 'app_id'),
                            path='assets', http_method='GET', name='assets.getAssetMultiple')
    def assets_get_multiple(self, query):
        return query

При развертывании этого каждый раз, когда я пытался получить доступ assets.getMultipleAssets это просто дает мне эту ошибкуraised BadRequestError(Key path element must not be incomplete: [ApplicationID: ]), Как ни странно, это происходит только с использованием метода @Model.query_method, I have other methods using the same system but using @Model.method and it just runs ok.

If I tried it in development server, sometimes it just gives me RuntimeError: BadRequestError('missing key id/name',) then if I just re-save the.py file and retry it, it will work (sometimes not and another re-save can also make the error happens again).

Кто-нибудь может сказать мне мою ошибку? Спасибо

1 ответ

Я думаю, что ваша проблема в том, как вы вызываете этот метод - это статический метод, поэтому вам нужно обращаться к нему через класс, а не через экземпляр (self):

    if AssetData.check_auth_app_id_pair(self.auth_id, value):
        self._app_id = value
    else:
        raise endpoints.BadRequestException('auth_id and app_id mismatch')