I’ve encountered a critical issue with Frappe’s module mapping system and wanted to bring it to the community’s attention. I’ve also opened a GitHub issue for tracking.
GitHub Issue: Module name collision on different apps installed in different sites · Issue #34895 · frappe/frappe · GitHub
The Problem
When two independent apps declare a module with the same name in their modules.txt, Frappe’s setup_module_map() function overwrites the module→app mapping, causing the last app in apps.txt to “win.” This leads to ImportError when loading DocTypes that belong to the first app.
Quick Example
If ERPNext has a “Stock” module and a custom app also declares “Stock”:
- Database says Stock belongs to ERPNext
- In-memory cache says Stock belongs to custom app
- Result: Frappe tries to load ERPNext DocTypes from the custom app → crash
Reproduction
- Create a custom app with a module named “Stock” in
modules.txt - Install ERPNext first, then the custom app
- ERPNext installation fails with
ImportError: No module named 'customapp.stock.doctype...'
Root Cause
In frappe/__init__.py (lines 1678-1688), the mapping simply overwrites without conflict resolution:
local.module_app[module] = app # Last app wins!
A warning is issued but doesn’t prevent the problem.
Discussion
Has anyone else encountered this? Any insights appreciated!