Overridden methods not working

I have setup ERPNext on local and production.
I am having a very strange issue.

TLDR;

On production setup my overridden methods are not working, however same methods works every time on my local setup.

More in-depth explanation:

I have a custom app where I have overriden few methods from ERPNext, let’s take example of get_emp_and_leave_details method from Salary Slip doctype. Below are the list of methods I have overridden.

In my custom app’s hooks file I have the following code along with the other code:

from erpnext.hr.doctype.salary_slip.salary_slip import SalarySlip
from myapp.modules.gourmet.salary_slip.salary_slip import get_emp_and_leave_details, 

SalarySlip.get_emp_and_leave_details = get_emp_and_leave_details

Versions
Bench => 5.1.0
Frappe => 12.8.3
ERPNext => 12.10.1

Use cases I have tested are:

  1. Local setup is not a production setup (it is running without supervisor) so I thought I should test my production server without supervisor and run it as development server but the error persists.
1 Like

Same issue i face a month ago it was so wired:upside_down_face:
4 out of 10 times my overridden function executed and 6 times native function executed. And same code is working on local machine 10/10

I just call overridden function in before save hook and then everything worked fine but i don’t think so this is right way.

@revant_one Can you please help ?

If it works, it’s one of the way!

In general, there should be a function which does the override patching that needs to be called before using the patched functionality.

e.g.

def my_patch():
    SalarySlip.get_emp_and_leave_details = get_emp_and_leave_details

call my_patch() before using SalarySlip.get_emp_and_leave_details functionality.

@revant_one But how strange the behavior of overridden function.

Working fine on local machine and same function doesn’t works on production :confused:

The hooks.py file in my custom app, that file is not intended for this purpose?
Because I am using that file for overriding all functions.

That’s not the correct way?

Any way is correct. hooks.py or in the code block itself, it depends on when you need to call the patched functionality.

1 Like

Firstly thank you for your time. Appreciate!

Ok but the question remains, why something is working on my local setup but not working in production.

And can you expplain a little bit about these points:

  1. When we should override a function in hooks.py and expect it to work
  2. When we should patch it via another function as you described above.