Monkey patch again: only this function won't be patched

Monkey patch is wonderful. See this How to override method in frappe? - #53 by charleslcso.

However, there is this function that seems not like patching: frappe/app.py/application(request).

Here is what’s in hook.py in my custom app:

import frappe.app
from custom_app.custom_app.custom_app import new_application

frappe.app.application = new_application

And in the actual custom_app.py, I have the same declaration too:

@Request.application
def new_application(request):

But this new_application(request) is never called.

Anyone experienced something similar?

The function you want to monkey patch is the WSGI application that’s used as an entry point - check the gunicorn or bench serve CLI (via Procfile in dev mode, and supervisor.conf in production).

You can update your supervisor conf to point the path to your newly defined function. Similarly, write a custom command for the developer server. Probably look into writing your own WSGI apps using Werkzeug for references if the Frappe codebase isn’t enough.

But this may not be what you want to do unless you’re well aware of the implications of your custom entrypoint. However, using hooks should be sufficient to extend Frappe to your use case.

2 Likes

Try moving from hooks.py to __ init __.py and restart server.