Hi,
I am trying to migrate one test db from v11 to v12 and there seems to be an error for patch as below:
Executing frappe.patches.v12_0.setup_comments_from_communications in rigplv12 (_db_name_)
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/aditya/v12/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
main()
File "/home/aditya/v12/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
click.Group(commands=commands)(prog_name='bench')
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/aditya/v12/env/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/aditya/v12/apps/frappe/frappe/commands/__init__.py", line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File "/home/aditya/v12/apps/frappe/frappe/commands/site.py", line 234, in migrate
migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
File "/home/aditya/v12/apps/frappe/frappe/migrate.py", line 48, in migrate
frappe.modules.patch_handler.run_all(skip_failing)
File "/home/aditya/v12/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all
run_patch(patch)
File "/home/aditya/v12/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch
if not run_single(patchmodule = patch):
File "/home/aditya/v12/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single
return execute_patch(patchmodule, method, methodargs)
File "/home/aditya/v12/apps/frappe/frappe/modules/patch_handler.py", line 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + ".execute")()
File "/home/aditya/v12/apps/frappe/frappe/patches/v12_0/setup_comments_from_communications.py", line 25, in execute
new_comment.db_insert()
File "/home/aditya/v12/apps/frappe/frappe/model/base_document.py", line 323, in db_insert
), list(d.values()))
File "/home/aditya/v12/apps/frappe/frappe/database/database.py", line 125, in sql
self.check_transaction_status(query)
File "/home/aditya/v12/apps/frappe/frappe/database/database.py", line 260, in check_transaction_status
frappe.throw(_("Too many writes in one request. Please send smaller requests"), frappe.ValidationError)
File "/home/aditya/v12/apps/frappe/frappe/__init__.py", line 360, in throw
msgprint(msg, raise_exception=exc, title=title, indicator='red')
File "/home/aditya/v12/apps/frappe/frappe/__init__.py", line 346, in msgprint
_raise_exception()
File "/home/aditya/v12/apps/frappe/frappe/__init__.py", line 315, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError: Too many writes in one request. Please send smaller requests
I have tried to resolve this issue by a simple hack in the patch by adding a simple loop to commit changes to db after every 10k entries as below:
reference file: frappe/setup_comments_from_communications.py at version-12 · frappe/frappe · GitHub
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doctype("Comment")
count = 0
for comment in frappe.get_all('Communication', fields = ['*'],
filters = dict(communication_type = 'Comment')):
new_comment = frappe.new_doc('Comment')
new_comment.comment_type = comment.comment_type
new_comment.comment_email = comment.sender
new_comment.comment_by = comment.sender_full_name
new_comment.subject = comment.subject
new_comment.content = comment.content or comment.subject
new_comment.reference_doctype = comment.reference_doctype
new_comment.reference_name = comment.reference_name
new_comment.link_doctype = comment.link_doctype
new_comment.link_name = comment.link_name
new_comment.creation = comment.creation
new_comment.modified = comment.modified
new_comment.owner = comment.owner
new_comment.modified_by = comment.modified_by
new_comment.db_insert()
count += 1
if count%10000 == 0:
frappe.db.commit()
print("Committed " + str(count))
# clean up
frappe.db.sql("delete from `tabCommunication` where communication_type = 'Comment'")
Simple hack above did tell me that the patch was trying to commit more than 800k comments in one go and due to which I guess the above error was coming.