如何使用patch_internal

问题描述 投票:1回答:1

在我的应用程序中,我有一个挂钩可以更新资源中的字段:在另一个post中,有人使用了patch_internal方法,但我不知道如何。

from my_application import app
from eve.methods.patch import patch_internal

def my_hook(...):
    with app.test_request_context():
        patch_internal("my_resource", payload={"bar": "bar_value"}, lookup={"foo": "foo_value"})

我尝试在PRESERVE_CONTEXT_ON_EXCEPTION = False中使用settings.py

根据我尝试的方式,我会选择其中一个

  • 原始请求的404,首先触发了钩子,

  • 或一个AssertionError:

Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File ".../lib/python2.7/site-packages/flask/app.py", line 1825, in wsgi_app
    ctx.auto_pop(error)
  File ".../lib/python2.7/site-packages/flask/ctx.py", line 374, in auto_pop
    self.pop(exc)
  File ".../lib/python2.7/site-packages/flask/ctx.py", line 357, in pop
% (rv, self)
AssertionError: Popped wrong request context.
(<RequestContext 'http://127.0.0.1:5001/' [GET] of eve> instead of <RequestContext 'http://127.0.0.1:5001/my_endpoint' [GET] of eve>)

我的问题是:

patch_internal的适当参数是什么?我该如何告诉夏娃,我想更改哪个项目?

eve
1个回答
2
投票

这是一个应该起作用的简单示例:

© www.soinside.com 2019 - 2024. All rights reserved.