简体   繁体   English

@EndpointsAliasProperty和@ Model.query_method导致BadRequestError(键路径元素不能不完整:…)

[英]@EndpointsAliasProperty and @Model.query_method causes BadRequestError(Key path element must not be incomplete:…)

Hey so right now I'm developing backend api using Google ProtoRPC and Endpoints. 嘿,现在我正在使用Google ProtoRPC和Endpoints开发后端api。 I'm using the endpoints-proto-datastore library. 我正在使用endpoints-proto-datastore库。

So strange things happen here, here is the EndpointsModel class 所以这里发生了奇怪的事情,这是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

and this is the API class 这是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

When I deploy this, everytime I tried to access assets.getMultipleAssets it just gives me this error raised BadRequestError(Key path element must not be incomplete: [ApplicationID: ]) . 当我部署它时,每次尝试访问assets.getMultipleAssets它只会给我raised BadRequestError(Key path element must not be incomplete: [ApplicationID: ])此错误raised BadRequestError(Key path element must not be incomplete: [ApplicationID: ]) Strangely enough this only happen to method using @Model.query_method , I have other methods using the same system but using @Model.method and it just runs ok. 奇怪的是,这仅发生在使用@Model.query_method方法上,我还有其他使用同一系统但使用@Model.method ,它运行正常。

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). 如果我在开发服务器中尝试过它,有时它只会给我RuntimeError: BadRequestError('missing key id/name',)然后如果我只是重新保存.py文件并重试它,它将正常工作(有时不行,而另一个-save也可以使错误再次发生)。

Can anyone tell me my mistake? 谁能告诉我我的错误? Thanks 谢谢

I think your problem is how you call this method - it's a static method, so you have to access it through class, not the instance (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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关键路径元素必须完整 - Key Path Element Must be complete razorpay.errors.BadRequestError:金额必须是 integer - razorpay.errors.BadRequestError: The amount must be an integer Django raise BadRequestError(msg) razorpay.errors.BadRequestError:金额必须是 integer。 退款时 - Django raise BadRequestError(msg) razorpay.errors.BadRequestError: The amount must be an integer. while refund 需要更好的解决方法BadRequestError:光标位置超出原始查询的范围 - Need a better workaround for BadRequestError: cursor position is outside the range of the original query 按键查询模型 - Query for model by key 避免或处理“BadRequestError:请求的查询已过期。”? - Avoiding or handling “BadRequestError: The requested query has expired.”? BadRequestError:BLOB,ENITY_PROTO或TEXT属性concise_topics必须在raw_property字段中 - BadRequestError: BLOB, ENITY_PROTO or TEXT property concise_topics must be in a raw_property field 打印json元素会导致TypeError:列表索引必须是整数,而不是str - Printing json element causes TypeError: list indices must be integers, not str Django - Raw查询必须包含主键 - Django - Raw query must include the primary key 无法查询“用户”:必须是“模型”实例 - Cannot query “user”: Must be “Model” instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM