简体   繁体   English

endpoints-proto-datastore-POST上必须填写该字段,但不要求GET

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

相关问题 具有长对象列表的对象作为带有w / endpoints-proto-datastore的字段 - Object with a long list of objects as a field w/endpoints-proto-datastore endpoints-proto-datastore无法摆脱默认过滤器 - endpoints-proto-datastore can't get rid of defaults filter 更新端点原始数据存储中的现有实体 - Updating existing entity in endpoints-proto-datastore 为什么Endpoints-proto-datastore不属于Google官方的Endpoints文档? - Why endpoints-proto-datastore is not part of official google endpoints documentation? GAE上的RESTful API:端点到原始数据存储区vs云端点 - RESTful API on GAE: endpoints-proto-datastore vs Cloud Endpoints endpoints-proto-datastore:返回不同的类然后输入类 - endpoints-proto-datastore: return different class then the input class 如何使用“endpoints-proto-datastore”在google appengine端点api中执行自定义查询? - How to perform custom queries in google appengine endpoints api using “endpoints-proto-datastore”? 重复时如何检索ndb.KeyProperty =使用端点原始数据存储真 - How to retrieve ndb.KeyProperty when repeated=True using endpoints-proto-datastore 使用Endpoints-proto-datastore从KeyProperty获取引用的实体 - Getting referred-to entity from KeyProperty using endpoints-proto-datastore 使用endpoints-proto-datastore,如何将属性传递给EndpointsModel中未包含的方法 - Using endpoints-proto-datastore, how do you pass attributes to a method that are not contained in the EndpointsModel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM