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)
  • 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.

1 Like

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()
frappe.db.set_global("installed_apps", json.dumps(installed_apps))

Thank you so much. That worked very well!

1 Like

If reordering apps.txt beware of running bench setup requirements or bench update:

There is also the required_apps hook value:

1 Like