无法创建具有objectid和data\u关系字段的条目

2024-04-20 10:24:12 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试插入与另一个文档相关的文档时遇到一些问题。API引发了一个完全没有详细信息的异常。在

我得到了以下奇怪的问题:

    "_error": {
        "code": 422, 
        "message": "Insertion failure: 1 document(s) contain(s) error(s)"
    }, 
    "_issues": {
        "exception": "'application'"
    }, 

我使用的是python3.4、eve0.5.3和mongodb3。详情如下:

架构:

^{pr2}$

所以交货和申请之间有一种关系。在这里,我将发布一个应用程序(我正在使用httpie,请参见https://github.com/jakubroztocil/httpie):

$ http POST :5000/api/applications label="toto"

回应:

HTTP/1.0 201 CREATED
Content-Length: 252
Content-Type: application/json
Date: Wed, 13 May 2015 08:35:14 GMT
Server: Eve/0.5.3 Werkzeug/0.10.4 Python/3.4.3

{
    "_created": "2015-05-13", 
    "_etag": "fc6492cb6ba36424a9e38113026c33e49a60189d", 
    "_id": "55530cc2962bf270efba95b2", 
    "_links": {
        "self": {
            "href": "applications/55530cc2962bf270efba95b2", 
            "title": "application"
        }
    }, 
    "_status": "OK", 
    "_updated": "2015-05-13"
}

现在,如果我尝试使用先前插入的对象中的_id插入传递,则会引发异常:

$ http POST :5000/api/deliveries label="toto" app="55530cc2962bf270efba95b2"

回应:

HTTP/1.0 422 UNPROCESSABLE ENTITY
Content-Length: 153
Content-Type: application/json
Date: Wed, 13 May 2015 08:39:42 GMT
Server: Eve/0.5.3 Werkzeug/0.10.4 Python/3.4.3

{
    "_error": {
        "code": 422, 
        "message": "Insertion failure: 1 document(s) contain(s) error(s)"
    }, 
    "_issues": {
        "exception": "'application'"
    }, 
    "_status": "ERR"
}

Tags: 文档httpmessagefailureapplicationexceptioncodeerror
1条回答
网友
1楼 · 发布于 2024-04-20 10:24:12

您的data_relation引用了错误的资源(端点)

根据您的POST请求(因为您没有发布您的DOMAIN定义),您最终将applications和{}定义定义为资源,因此您应该在数据关系中引用{}(复数)。在

请尝试以下更新:

delivery_schema = {
    'label': {
        'type': 'string',
        'required': True,
        'empty': False,
        'unique': True,
    },
    'app': {
            'type': 'objectid',
            'required': True,
            'data_relation': {
                # replace 'application' with 'applications' as
                # that's the actual endpoint (resource) name.
                'resource': 'applications',
                'embeddable': True
            },
    },
}

相关问题 更多 >