Order of apps to be installed

Hi there,

I am developing an app that depends on hrms, which in turn depends on ERPNext.
Now my app is installed after ERPNext but before hrms. Therefore, my changes are not applied.

Is there a way to define the order in which the apps are installed and migrated?

Thank you so much!

Check the apps.txt file in the sites folder and rearrange the order. This should solve the issue.

I did this already and no luck. Basically, this changes the order how the apps are shown in bench list-apps, but the order in bench migrate is a completely different one. The order in migrate is always exactly the same no matter what I change. Is there anything I need to do that the changes are applied?

It “should” be possible to define the dependencies using:

  • requirements.txt (Version 13 and earlier)
    or
  • pyproject.toml (Version 14+)

You could specific both ‘hrms’ and ‘erpnext’ as Python dependencies. This would prevent your app from installing, unless the other 2 are installed.

In the past, ERPNext actually had Frappe as a dependency. Ankush had to remove that in April 2021 for technical reasons. But you can see what that looked like here:
chore: remove frappe from requirements.txt · frappe/erpnext@64a38f5 · GitHub

As for the order of operations performed by 'bench migrate'? I think it’s unpredictable:

  1. 'sync_all()' calls 'frappe.get_installed_apps() without a sort argument:
    frappe/sync.py at develop · frappe/frappe · GitHub

  2. 'get_installed_apps' generates a Python List. But there isn’t a default sorting.
    get_installed_apps()

It’s actually pretty simple. There’s a global value in the database called installed_apps - it’s in the sequence of installation. Every time an app is installed, it gets added at the end of installed_apps.

The sort parameter to get_installed_apps needs to be deprecated - it’s not ideal for multi-tenancy (see attempt).

To move your custom app to the end of this list, you can just execute the following code in bench console:

installed_apps = frappe.get_installed_apps()
installed_apps.remove("your-app-name")
installed_apps.append("your-app-name")
frappe.db.set_global("installed_apps", json.dumps(installed_apps))
frappe.db.commit()

Thank you so much. That worked very well!

1 Like