<div dir="ltr">Hi Matthew,<br><br>If you only want to disable after_insert hook in a single entity class for the duration of the script execution, you can just delete the method as you suggested.<br><br>If you want to temporary disable after_insert hook in all entity classes you can use the following context manager, which temporary overrides Entity._after_save_ internal method:<br><br><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>from contextlib import contextmanager</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>from pony.orm.core import Entity</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>@contextmanager</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>def disable_after_insert_hooks():</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>prev_after_save = Entity._after_save_</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>try:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>def after_save(obj, status):</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>if status == 'inserted':</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>pass # do nothing</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>else:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>prev_after_save(obj, status)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>Entity._after_save_ = after_save</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>yield</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>finally:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>Entity._after_save_ = prev_after_save<br><br>Usage:<br><br> with disable_after_insert_hooks(), db_session:<br> <do something><br><br><br>Regards,<br>Alexander<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 13, 2016 at 7:57 PM, Matthew Bell <span dir="ltr"><<a href="mailto:matthewrobertbell@gmail.com" target="_blank">matthewrobertbell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Of course, as soon as I send the email, I figure it out :)<br><br></div>del MyModel.after_insert<br><br></div>(The method won't be needed again in this process)<br></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On 13 September 2016 at 17:40, Matthew Bell <span dir="ltr"><<a href="mailto:matthewrobertbell@gmail.com" target="_blank">matthewrobertbell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hello,<br><br></div>For a very specific circumstance, I need to disable the after_insert hook on a pony model, is there a clean way of doing this?<br><br></div>Thanks!<span><font color="#888888"><br clear="all"><div><div><div><br>-- <br><div data-smartmail="gmail_signature">Regards,<br><br>Matthew Bell<br></div>
</div></div></div></font></span></div>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br><div data-smartmail="gmail_signature">Regards,<br><br>Matthew Bell<br></div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" rel="noreferrer" target="_blank">https://mailman-mail5.<wbr>webfaction.com/listinfo/<wbr>ponyorm-list</a><br>
<br></blockquote></div><br></div>