[英]@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.