Best practice to resolve/prioritize conflicts

Hello, I’m new to Frappe development and I’m looking to develop custom apps. However, I thought about a scenario when 2 independent apps might try to add/modify the exact same thing, there will be conflicts (For example, 2 custom apps might try to add/modify the same custom field on an ERPNext doctype at the same time, with no knowledge of each other’s existence).

My question is, how do we know which app that will be prioritized when conflicts happen?

I’ve read articles and forums saying that it is basically the “last ran app/script” that will be prioritized (as it overwrites anything before it), but how can we know/control which app/script will be ran last? Or is there some best practices to develop custom apps that will avoid this conflicts possibility altogether?

Example scenario that I made:
Conflict app 1

#conflict_app_1
import frappe

def set_status_win(doc, method):
    if doc.condition == "True":
        doc.conflict = "App 1 wins"

The hooks:

doc_events = {
    "Test Conflict 1": {
        "validate": "conflict_app_1.api.set_status_win"
    }
}

Conflict app 2

#conflict_app_2
import frappe

def set_status_win(doc, method):
    if doc.condition == "True":
        doc.conflict = "App 2 wins"

The hooks

doc_events = {
    "Test Conflict 1": {
        "validate": "conflict_app_2.api.set_status_win"
    }
}

In the example scenario I provided, conflict_app_2’s code always win in the conflict.

I’ll appreciate any help and information :slight_smile:
Thank you