[英]endpoints-proto-datastore - field should be required on POST but not GET
Let's say I have a Model with two mandatory fields: 假设我有一个带有两个必填字段的模型:
class ExampleModel(EndpointsModel):
attr1 = ndb.StringProperty(required=True)
attr2 = ndb.StringProperty(required=True)
Then I want to use endpoints-proto-datastore to query on either attr1 or attr2: 然后,我想使用的端点,原数据存储到在任 attR1位或attR2位查询:
@ExampleModel.query_method(query_fields=('attr1', 'attr2'),
path='example', name='list')
def example_list(self, query):
return query
This fails if I only provide one of the fields - from API Explorer it's a required field, but the API itself returns: 如果我仅提供以下字段之一,则此操作将失败-从API资源管理器中这是必填字段,但API本身会返回:
{
"error": {
"code": 400,
"errors": [
{
"domain": "global",
"message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field attr2)",
"reason": "badRequest"
}
],
"message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field attr2)"
}
}
Obviously I could mark them as not required, then handle the check within the application code - but I was wondering if someone else had come up with a better solution. 显然,我可以将它们标记为不需要,然后在应用程序代码中进行检查-但我想知道其他人是否提出了更好的解决方案。
Many thanks 非常感谢
This is an old question but I ran into the same confusion. 这是一个老问题,但我遇到了同样的困惑。 This was the answer I found.
这就是我找到的答案。 Basically if you want to make something mandated on Post but not get you need to make a custom proto class.
基本上,如果您想在Post上进行一些强制性的操作,但又不想得到,则需要制作一个自定义的原型类。 Which can only be used with method and not query_method.
只能与method一起使用,而不能与query_method一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.