Updating. We will be back in a few moments...No system available

After trying to update --upgrade I got this:
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.IntegrityError: (1062, “Duplicate entry ‘General-mario_donadio@yahoo.com’ for key ‘unique_newsletter_list_email’”)

I run: bench frappe --latest but same results.
I don’n know how to deal with this error. I would appreciate your help. Site and system not available now. Thank you!

Which version you are using?

@camilopianos

I need to know which patch is failing. Please always put complete tracebacks from the console.

-Anand.

I’m on v5 and frappe6
This is the complete traceback:
Updating frappe : [========================================]
Updating erpnext : [======== ]Traceback (most recent call last):
File “/home/cami/frappe-bench/env/bin/frappe”, line 9, in
load_entry_point(‘frappe==4.5.0’, ‘console_scripts’, ‘frappe’)()
File “/home/cami/frappe-bench/apps/frappe/frappe/cli.py”, line 53, in main
File “/home/cami/frappe-bench/apps/frappe/frappe/cli.py”, line 83, in run
File “/home/cami/frappe-bench/apps/frappe/frappe/cli.py”, line 67, in new_fn
File “/home/cami/frappe-bench/apps/frappe/frappe/cli.py”, line 425, in latest
File “/home/cami/frappe-bench/apps/frappe/frappe/model/sync.py”, line 19, in sync_all
sync_for(app, force, verbose=verbose)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/sync.py”, line 43, in sync_for
import_file_by_path(doc_path, force=force)
File “/home/cami/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 54, in import_file_by_path
import_doc(doc, force=force, data_import=data_import, pre_process=pre_process)
File “/home/cami/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 122, in import_doc
doc.insert()
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 196, in insert
self.run_post_save_methods()
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 587, in run_post_save_methods
self.run_method(“on_update”)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 531, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 663, in composer
return composed(self, method, *args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 646, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 525, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 122, in on_update
self.run_module_method(“after_doctype_insert”)
File “/home/cami/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 131, in run_module_method
getattr(module, method)()
File “/home/cami/frappe-bench/apps/erpnext/erpnext/crm/doctype/newsletter_list_subscriber/newsletter_list_subscriber.py”, line 13, in after_doctype_insert
frappe.db.add_unique(“Newsletter List Subscriber”, (“newsletter_list”, “email”))
File “/home/cami/frappe-bench/apps/frappe/frappe/database.py”, line 777, in add_unique
add unique %s(%s)“”" % (doctype, constraint_name, ", ".join(fields)))
File “/home/cami/frappe-bench/apps/frappe/frappe/database.py”, line 146, in sql
self._cursor.execute(query)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.IntegrityError: (1062, “Duplicate entry ‘General-mario_donadio@yahoo.com’ for key ‘unique_newsletter_list_email’”)

Many thanks!

After update --upgrade:

Updating erpnext : [======== ]Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/cami/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/cami/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 664, in call
return self.main(*args, **kwargs)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 644, in main
rv = self.invoke(ctx)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 991, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 991, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 837, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 464, in invoke
return callback(*args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/commands.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/commands.py”, line 216, in migrate
frappe.model.sync.sync_all(verbose=context.verbose)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/sync.py”, line 19, in sync_all
sync_for(app, force, verbose=verbose)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/sync.py”, line 43, in sync_for
import_file_by_path(doc_path, force=force)
File “/home/cami/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 54, in import_file_by_path
import_doc(doc, force=force, data_import=data_import, pre_process=pre_process)
File “/home/cami/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 122, in import_doc
doc.insert()
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 196, in insert
self.run_post_save_methods()
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 587, in run_post_save_methods
self.run_method(“on_update”)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 531, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 663, in composer
return composed(self, method, *args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 646, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/cami/frappe-bench/apps/frappe/frappe/model/document.py”, line 525, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/cami/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 122, in on_update
self.run_module_method(“after_doctype_insert”)
File “/home/cami/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 131, in run_module_method
getattr(module, method)()
File “/home/cami/frappe-bench/apps/erpnext/erpnext/crm/doctype/newsletter_list_subscriber/newsletter_list_subscriber.py”, line 13, in after_doctype_insert
frappe.db.add_unique(“Newsletter List Subscriber”, (“newsletter_list”, “email”))
File “/home/cami/frappe-bench/apps/frappe/frappe/database.py”, line 777, in add_unique
add unique %s(%s)“”" % (doctype, constraint_name, ", ".join(fields)))
File “/home/cami/frappe-bench/apps/frappe/frappe/database.py”, line 146, in sql
self._cursor.execute(query)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/cami/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.IntegrityError: (1062, “Duplicate entry ‘General-mario_donadio@yahoo.com’ for key ‘unique_newsletter_list_email’”)
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 9, in
load_entry_point(‘bench==0.1’, ‘console_scripts’, ‘bench’)()
File “/home/cami/bench-repo/bench/cli.py”, line 60, in cli
bench()
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 610, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 590, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 936, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 782, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 416, in invoke
return callback(*args, **kwargs)
File “/home/cami/bench-repo/bench/cli.py”, line 240, in _update
update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, upgrade, force=force)
File “/home/cami/bench-repo/bench/cli.py”, line 270, in update
patch_sites(bench=bench_path)
File “/home/cami/bench-repo/bench/utils.py”, line 158, in patch_sites
run_frappe_cmd(‘–site’, ‘all’, ‘migrate’, bench=bench)
File “/home/cami/bench-repo/bench/utils.py”, line 489, in run_frappe_cmd
raise CommandFailedError(args)
bench.utils.CommandFailedError: (‘–site’, ‘all’, ‘migrate’)

This is a script that should solve the problem, though take a backup just to be safe as the script is untested.

bench --site {sitename} backup
bench --site {sitename} console

In the console:

%edit

Paste this script and save the edit mode. If it is vim, you will have to press esc and then :wq

duplicates = frappe.db.sql("""select newsletter_list, email, count(name) 
	from `tabNewsletter List Subscriber` 
	group by newsletter_list, email 
	having count(name) > 1""")

# delete all duplicates except 1
for newsletter_list, email, count in duplicates:
	frappe.db.sql("""delete from `tabNewsletter List Subscriber`
		where newsletter_list=%s and email=%s limit %s""", (newsletter_list, email, count-1))

frappe.db.commit()

Once this is executed, you can run bench update --upgrade --force to continue with the update.

After that you will need to run:

bench setup socketio
bench setup redis-async-broker
bench setup redis-cache
bench setup procfile

Thanks,
Anand.

Thank you so much!!!

Hi Anand,

I am apparently in same situation as camilopianos, but if I run your script I get a name error:

NameError: name ‘frappe’ is not defined
Out[1]: ‘duplicates = frappe.db.sql(“”“select newsletter_list, email, count(name) \n\tfrom tabNewsletter List Subscriber \n\tgroup by newsletter_list, email \n\thaving count(name) > 1"”“)\n\n# delete all duplicates except 1\nfor newsletter_list, email, count in duplicates:\n\tfrappe.db.sql(”““delete from tabNewsletter List Subscriber\n\t\twhere newsletter_list=%s and email=%s limit %s””", (newsletter_list, email, count-1))\n\nfrappe.db.commit()\n\n’

What am I doing wrong?

Many thanks and kind regards from Spain,

Alb

Hi!

I have the same problem :confused: @pagliaso do you solve it?

Thx

Hi Maurice!

Yes, I solved the issue, but I don’t remember what I did, sorry?!

Maybe it was something wrong on how I introduced the script, or maybe I separated it and divided the script on several parts that I could execute succesfully, but I didn’t documented it as I should and I totally forgot. Also maybe I had found something in other thread of the Forum.

Good luck and kind regards from Spain,

Alberto

Thank you for your answer… Unfortunately, I can’t find any solutions :frowning: