Python Eve patch_internal set etag
<p>I am trying to make an <code>on_insert</code> event hook for a document from schema A, call eve's <code>patch_internal</code> to a document from schema B. </p>

<p>Since the request triggering the event hook is a <code>POST</code> for A, there's no <code>If-Match</code> header with the necessary B <code>etag</code> in flask request.</p>

<p>I've tried to set the value on the flask request before the <code>patch_internal</code> with <code>flask.request.if_match</code>, but seems it is not possible since it is a frozenset.</p>

<p>How can I set the <code>etag</code> for the <code>patch_internal</code> call?</p>

<p>In summary, the creation of a document updates other document with different schema. Can I do this?</p>

<p>Thanks.</p>

<p>Can't say this is the best way, but it works.</p>

<p>Creating a new request context to call <code>patch_internal</code>, and setting the <code>etag</code> on the <code>environ</code> used to create it, works. Below an example:</p>

<pre><code>from flask import request, current_app
from eve.methods.patch import patch_internal

...

new_environ = request.environ
new_env['HTTP_IF_MATCH'] = patched_document['_etag']
    with current_app.request_context(new_env):
        result = patch_internal('my_document_b', {'updated_key': value},  {'_id': my_document_b['_id']})
...
</code></pre>

python flask eve