The issue involves core module mapping logic and requires careful handling of app dependencies.
The issue describes a module name collision problem in Frappe's module mapping system, where conflicting module names across apps cause ImportError. The fix requires modifying the core module mapping logic in `frappe/__init__.py` and potentially adding validation during app installation. The complexity is high due to the need to maintain backward compatibility and handle app dependencies correctly.
When two independent apps declare a module with the same name in their modules.txt file, Frappe's module mapping system causes ImportError during app installation.
The root cause is in frappe/__init__.py:setup_module_map() which builds the local.module_app dictionary by iterating through apps and overwrites any existing module→app mapping when a duplicate module name is found. This means the last app processed wins, regardless of which app actually owns a specific DocType.
This creates a critical problem:
tabModule Def) show the first app that installed the modulefrappe.local.module_app) points to the last app in iteration orderOutput of bench version
frappe 15.x
erpnext 15.x
Affected file: frappe/frappe/__init__.py lines 1649-1688 (setup_module_map)
Create two independent apps that both declare a module named "Stock" in their modules.txt:
erpnext): Contains module "Stock" with DocType "Repost Item Valuation"appcustom): Contains module "Stock" but WITHOUT "Repost Item Valuation"Add both apps to sites/apps.txt in this order:
frappe
erpnext
appcustom
Create a new site and install App A (erpnext):
bench new-site testsite
bench --site testsite install-app erpnext
Installation fails with:
ImportError: Module import failed for Repost Item Valuation, the DocType you're trying to open might be deleted.
Error: No module named 'appcustom.stock.doctype.repost_item_valuation'
What happens internally:
setup_module_map(), the function iterates through apps in ordererpnext: sets local.module_app["stock"] = "erpnext"Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!