Module Import Error when doing doc event hook

Hi,

i am using vagrant for developing. I have code like this in my custom app hooks

doc_events = {
    "Customer": {
        "onload": "custom_app.scripts.customer.update_customer_methods"
    },
}

On vagrant everything work correct. But when i push this code to my prod. server i am getting error:
No module named scripts.customer

Did you met similiar problem?

I don’t thing that this is frappe/erpnext problem, because both instances has same versions. Maybe there is some environment settings problem.

Other paths are working correctly, only when i put file to custom folder.

THANKS

Can somebody help with that ? I am still facing this issue.

the only thing I can think of, is really a problem with the path.
If you try to import that in bench console, do you get the same error?
the scripts directory is in the same emplacement as hook.py?

*note: usually people write hooks methods in custom_app.events.py directly. I don’t think it’s part of the issue, I’m just saying it might be a good practice.

THANKS FOR YOUR FAST ANSWER :slight_smile:

Yes i also mean, that it is something with path.

If you try to import that in bench console, do you get the same error?

You mean import like?

import app_name
app_name..scripts.customer.update_customer_methods

or?

the scripts directory is in the same emplacement as hook.py?

yes i tried also app_name/module_name/script.py, an app_name/my_dir_name/script.py

*note: usually people write hooks methods in custom_app.events.py directly. I don’t think it’s part of the issue, I’m just saying it might be a good practice.

Thanks for recommendation. Yes i know that, but when i have lot of hooks i want have it splitted to more files.

But i tried this now: when i add all hooks to one file for example events.py, and this file is placed inside same directory as hooks.py, it is working, bow when i put it inside another folder then this hook is not working.

For now my fix is do it in this way. But i want solve this in future, because it is very risky whnen dev enviroment working different than production.

sorry, my name wasn’t attached to your post, so I never received the notification. Did you figure out the problem?

Hi, thanks for your answer. No I did not find solution :slight_smile:

Well you found the problem: a method called from the hook should never be in a new directory. You need to place it with a doctype (where you have the files .py/.js) or in the same hierarchy as hook.py

I didn’t notice you had a new folder for it. ERPNext doesn’t like that, I don’t know why…
The fact that vagrant let it pass is weird :thinking:

1 Like

Thanks.

It’s nice to know that. I don’t know, maybe it is caused by different path settings in environment.

In your new directory, check if you “[double underscore]init__.py” file. If not create a blank one and then try.

Sounds good. I will try and ping you back.