Skip to content

bench migrate fails with stale module path after moving module between apps in development mode  #1674

@Sendipad

Description

@Sendipad

#Description
When working in development mode with a test site, moving a module (and its Doctypes) from one custom app to another can leave stale module references.

Even after uninstalling the old app and restarting bench, bench --site migrate fails with a ModuleNotFoundError pointing to the old app path, although the app is no longer installed.


Steps to Reproduce

  1. Enable developer mode.

bench set-config -g developer_mode 1

  1. Create a custom app:

bench new-app old_app

bench --site test.local install-app old_app

  1. Create a custom module and one or more Doctypes inside old_app.

  2. Create another custom app:

bench new-app new_app

bench --site test.local install-app new_app

  1. Move the module directory from old_app to new_app:

apps/old_app/old_app/old_module

→ apps/new_app/new_app/new_module

  1. Update imports, module paths, and modules.txt accordingly.

  2. Uninstall the old app:

bench --site test.local uninstall-app old_app

  1. Restart bench:

bench restart

  1. Create a new Doctype or modify existing ones.

  2. Run migrate:

bench --site test.local migrate

Expected Behavior

Migration should complete successfully.

No references to old_app should remain after uninstalling it.

Bench should not attempt to import modules from an uninstalled app.


Actual Behavior

Migration fails with an error similar to:

ModuleNotFoundError: No module named 'old_app.old_module'

The error references a path from the uninstalled app, even though:

The app is no longer installed

The module exists in the new app

Bench has been restarted


Additional Notes / Observations

This appears to be caused by stale metadata stored in:

DocType.module

tabModule Def

cached Python imports

possibly DocType.module values in the database

Manual cleanup may temporarily fix the issue:

UPDATE tabDocType

SET module = 'New Module'

WHERE module = 'Old Module';

However, this should be handled automatically during:

app uninstall

module relocation

migrate


Environment

Frappe version: 15.9

Bench version: 5.27.0

OS: Linux

Database: MariaDB

Mode: Developer mode enabled


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions