Frappe Async tasks error!

Hi frappe team.

Happy new year!

I’am having some troubling in understand the error that i’am getting in some circumstances. The error is described below. I get the error when i ask for two reports (in this case jasper reports) one after another. The first report take two must time but after a minute or two i get the report. When i’am waiting for the first report if i make a new request (another report) i get the error after a minute, but i can see the reports anyway.

This long waiting occur only when i start frappe (bench start), after the first report and after waiting for a minute or two the next reports don’t take any time at all.

I put some prints to see if the long wait is in my code and i came to the conclusion that is not. The wait is in frappe.async.handler or in frappe.tasks.run_async_task that only call my function after the long wait.

The error is:

    [2016-01-04 19:33:22,096: ERROR/MainProcess] Task frappe.tasks.enqueue_events_for_site[6f135289-4134-40f1-83d7-4dfc33333b21] raised unexpected: TypeError('connect() argument 2 must be string, not None',)
19:33:22 worker.1             | Traceback (most recent call last):
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
19:33:22 worker.1             |     R = retval = fun(*args, **kwargs)
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
19:33:22 worker.1             |     return self.run(*args, **kwargs)
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/tasks.py", line 141, in enqueue_events_for_site
19:33:22 worker.1             |     enqueue_events(site)
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 22, in enqueue_events
19:33:22 worker.1             |     if is_scheduler_disabled():
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 131, in is_scheduler_disabled
19:33:22 worker.1             |     return not frappe.utils.cint(frappe.db.get_single_value("System Settings", "enable_scheduler"))
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 515, in get_single_value
19:33:22 worker.1             |     tabSingles where doctype=%s and field=%s""", (doctype, fieldname))
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 105, in sql
19:33:22 worker.1             |     self.connect()
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 51, in connect
19:33:22 worker.1             |     use_unicode=True, charset='utf8')
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
19:33:22 worker.1             |     return Connection(*args, **kwargs)
19:33:22 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
19:33:22 worker.1             |     super(Connection, self).__init__(*args, **kwargs2)
19:33:22 worker.1             | TypeError: connect() argument 2 must be string, not None

Thanks.

@luisfmfernandes if you are using the latest version of frappe, share the Error Snapshot with the locals variables expanded, it will be helpfull to understand and solve this question.

Hi @max_morais_dmm i’am using the latest version of frappe but there is no Error Snapshot made for this error.

And now i just start frappe (bench start) and occur again the error and again no Error Snapshot, the error is:

08:51:26 worker.1             | Traceback (most recent call last):
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
08:51:26 worker.1             |     R = retval = fun(*args, **kwargs)
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
08:51:26 worker.1             |     return self.run(*args, **kwargs)
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/tasks.py", line 141, in enqueue_events_for_site
08:51:26 worker.1             |     enqueue_events(site)
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 22, in enqueue_events
08:51:26 worker.1             |     if is_scheduler_disabled():
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 131, in is_scheduler_disabled
08:51:26 worker.1             |     return not frappe.utils.cint(frappe.db.get_single_value("System Settings", "enable_scheduler"))
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 515, in get_single_value
08:51:26 worker.1             |     tabSingles where doctype=%s and field=%s""", (doctype, fieldname))
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 105, in sql
08:51:26 worker.1             |     self.connect()
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/apps/frappe/frappe/database.py", line 51, in connect
08:51:26 worker.1             |     use_unicode=True, charset='utf8')
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
08:51:26 worker.1             |     return Connection(*args, **kwargs)
08:51:26 worker.1             |   File "/Users/saguas/erpnext4/erpnext/frappe_v5/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
08:51:26 worker.1             |     super(Connection, self).__init__(*args, **kwargs2)
08:51:26 worker.1             | TypeError: connect() argument 2 must be string, not None

Thanks,
Luis.

@luisfmfernandes this could be due to tasks linked to a missing site (or locals.site getting corrupted). Not sure how they are getting in though.

Thanks @rmehta, i will check!