builtins.KeyError: 'doctype' when running migrate

I wanted to Customize an ERPNext doctype - Quotation. I added a field and did ‘Export Customizations’ into my custom app module. This created a json file in custom folder but it has multiple other fields (that I didn’t touch), probably comes from customizations by other apps I have installed on my site. This works fine in my local site. But when I run ‘bench migrate’ it throws the following KeyError. I am not sure what’s happening. Happening with other ERPNext doctypes as well.

How can I resolve this?

Traceback with variables (most recent call last):
File “/usr/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
mod_name = ‘frappe.utils.bench_helper’
alter_argv = True
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, origin=‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
code = <code object at 0x7f3c8775a130, file “/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
main_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, origin=‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.10/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.10/json/init.py’>, ‘os’: <module ‘os’ from ‘/usr/lib/python3.10/os.py’>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.10/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.10/warnings.py’>, ‘Path’: …
File “/usr/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
code = <code object at 0x7f3c8775a130, file “/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
run_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, origin=‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.10/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.10/json/init.py’>, ‘os’: <module ‘os’ from ‘/usr/lib/python3.10/os.py’>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.10/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.10/warnings.py’>, ‘Path’: …
init_globals = None
mod_name = ‘main
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>, origin=‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
pkg_name = ‘frappe.utils’
script_name = None
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7f3c88d6a380>
fname = ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’
cached = ‘/home/randhir/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’
File “/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 114, in
main()
…skipped… 27 vars
File “/home/randhir/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 20, in main
click.Group(commands=commands)(prog_name=“bench”)
commands = {‘frappe’: , ‘get-frappe-commands’: , ‘get-frappe-help’: }
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1157, in call
return self.main(*args, **kwargs)
self =
args = ()
kwargs = {‘prog_name’: ‘bench’}
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1078, in main
rv = self.invoke(ctx)
self =
args = [‘frappe’, ‘migrate’]
prog_name = ‘bench’
complete_var = None
standalone_mode = True
windows_expand_args = True
extra = {}
ctx = <click.core.Context object at 0x7f3c87dea140>
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
_process_result = <function MultiCommand.invoke.._process_result at 0x7f3c87787e20>
args = [‘migrate’]
cmd_name = ‘frappe’
cmd =
sub_ctx = <click.core.Context object at 0x7f3c87626110>
ctx = <click.core.Context object at 0x7f3c87dea140>
self =
class = <class ‘click.core.MultiCommand’>
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
_process_result = <function MultiCommand.invoke.._process_result at 0x7f3c876449d0>
args =
cmd_name = ‘migrate’
cmd =
sub_ctx = <click.core.Context object at 0x7f3c87627490>
ctx = <click.core.Context object at 0x7f3c87626110>
self =
class = <class ‘click.core.MultiCommand’>
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
self =
ctx = <click.core.Context object at 0x7f3c87627490>
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
_Context__self = <click.core.Context object at 0x7f3c87627490>
_Context__callback = <function migrate at 0x7f3c877afa30>
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
ctx = <click.core.Context object at 0x7f3c87627490>
File “/home/randhir/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py”, line 33, in new_func
return f(get_current_context(), *args, **kwargs)
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
f = <function migrate at 0x7f3c877af7f0>
File “/home/randhir/frappe-bench/apps/frappe/frappe/commands/init.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
ctx = <click.core.Context object at 0x7f3c87627490>
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
profile = False
f = <function migrate at 0x7f3c877af760>
File “/home/randhir/frappe-bench/apps/frappe/frappe/commands/site.py”, line 613, in migrate
SiteMigration(
context = {‘sites’: [‘wellnest-web.local’], ‘force’: False, ‘verbose’: False, ‘profile’: False}
skip_failing = False
skip_search_index = False
activate_by_import = <module ‘traceback_with_variables.activate_by_import’ from ‘/home/randhir/frappe-bench/env/lib/python3.10/site-packages/traceback_with_variables/activate_by_import.py’>
SiteMigration = <class ‘frappe.migrate.SiteMigration’>
site = ‘wellnest-web.local’
File “/home/randhir/frappe-bench/apps/frappe/frappe/migrate.py”, line 187, in run
self.post_schema_updates()
self = <frappe.migrate.SiteMigration object at 0x7f3c87627520>
site = ‘wellnest-web.local’
filelock = <function filelock at 0x7f3c847928c0>
File “/home/randhir/frappe-bench/apps/frappe/frappe/migrate.py”, line 52, in wrapper
raise e
args = (<frappe.migrate.SiteMigration object at 0x7f3c87627520>,)
kwargs = {}
method = <function SiteMigration.post_schema_updates at 0x7f3c84792560>
File “/home/randhir/frappe-bench/apps/frappe/frappe/migrate.py”, line 44, in wrapper
ret = method(*args, **kwargs)
args = (<frappe.migrate.SiteMigration object at 0x7f3c87627520>,)
kwargs = {}
method = <function SiteMigration.post_schema_updates at 0x7f3c84792560>
File “/home/randhir/frappe-bench/apps/frappe/frappe/migrate.py”, line 142, in post_schema_updates
sync_customizations()
self = <frappe.migrate.SiteMigration object at 0x7f3c87627520>
File “/home/randhir/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 113, in sync_customizations
sync_customizations_for_doctype(data, folder, fname)
app = None
apps = [‘frappe’, ‘wellnest’, ‘payments’, ‘erpnext’, ‘india_compliance’]
app_name = ‘wellnest’
module_name = ‘wellnest’
folder = ‘/home/randhir/frappe-bench/apps/wellnest/wellnest/wellnest/custom’
fname = ‘quotation.json’
f = <_io.TextIOWrapper name=‘/home/randhir/frappe-bench/apps/wellnest/wellnest/wellnest/custom/quotation.json’ mode=‘r’ encoding=‘UTF-8’>
data = {‘custom_fields’: [{‘_assign’: None, ‘_comments’: None, ‘_liked_by’: None, ‘_user_tags’: None, ‘allow_in_quick_entry’: 0, ‘allow_on_submit’: 0, ‘bold’: 0, ‘collapsible’: 0, ‘collapsible_depends_on’: None, ‘columns’: 0, ‘creation’: ‘2024-08-23 16:41:20.809007’, ‘default’: None, ‘depends_on’: None, ‘description’: None, ‘docstatus’: 0, ‘dt’: ‘Quotation’, ‘fetch_from’: None, ‘fetch_if_empty’: 0, ‘fieldname’: ‘custom_originating_lead’, ‘fieldtype’: ‘Link’, ‘hidden’: 0, ‘hide_border’: 0, ‘hide_days’: 0, ‘hide_seconds’: 0, ‘idx’: 11, ‘ignore_user_permissions’: 0, ‘ignore_xss_filter’: 0, ‘in_global_search’: 0, ‘in_list_view’: 0, ‘in_preview’: 0, ‘in_standard_filter’: 0, ‘insert_after’: ‘valid_till’, ‘is_system_generated’: 0, ‘is_virtual’: 0, ‘label’: ‘Originating Lead’, ‘length’: 0, ‘link_filters’: None, ‘mandatory_depends_on’: None, ‘modified’: ‘2024-08-23 16:41:20.809007’, ‘modified_by’: ‘Administrator’, ‘module’: None, ‘name’: ‘Quotation-custom_originating_lead’, ‘no_copy’: 0, ‘non_negative…
File “/home/randhir/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 122, in sync_customizations_for_doctype
doctype = data[“doctype”]
filename = ‘quotation.json’
validate_fields_for_doctype = <function validate_fields_for_doctype at 0x7f3c83fa9a20>
data = {‘custom_fields’: [{’_assign’: None, ‘_comments’: None, ‘_liked_by’: None, ‘_user_tags’: None, ‘allow_in_quick_entry’: 0, ‘allow_on_submit’: 0, ‘bold’: 0, ‘collapsible’: 0, ‘collapsible_depends_on’: None, ‘columns’: 0, ‘creation’: ‘2024-08-23 16:41:20.809007’, ‘default’: None, ‘depends_on’: None, ‘description’: None, ‘docstatus’: 0, ‘dt’: ‘Quotation’, ‘fetch_from’: None, ‘fetch_if_empty’: 0, ‘fieldname’: ‘custom_originating_lead’, ‘fieldtype’: ‘Link’, ‘hidden’: 0, ‘hide_border’: 0, ‘hide_days’: 0, ‘hide_seconds’: 0, ‘idx’: 11, ‘ignore_user_permissions’: 0, ‘ignore_xss_filter’: 0, ‘in_global_search’: 0, ‘in_list_view’: 0, ‘in_preview’: 0, ‘in_standard_filter’: 0, ‘insert_after’: ‘valid_till’, ‘is_system_generated’: 0, ‘is_virtual’: 0, ‘label’: ‘Originating Lead’, ‘length’: 0, ‘link_filters’: None, ‘mandatory_depends_on’: None, ‘modified’: ‘2024-08-23 16:41:20.809007’, ‘modified_by’: ‘Administrator’, ‘module’: None, ‘name’: ‘Quotation-custom_originating_lead’, ‘no_copy’: 0, 'non_negative…
folder = ‘/home/randhir/frappe-bench/apps/wellnest/wellnest/wellnest/custom’
builtins.KeyError: ‘doctype’

Wanted to add that I removed all the fields, except for the one I want to add, from the custom json file generated by ‘Export Customizations’. Happening time and again.

Any help please? @buildwithhussain