Try ERPNext Buy Support Partners Foundation

[VS Code] No Object Bound to DB - debugging frappe.db.sql

Hi, guys!

I am trying to setup my Visual Code as the debugger for frappe but had a roadblock for a week and a half now. I am trying to debug this code to test the frappe.db.sql cmd:

import frappe

@frappe.whitelist()
def queryDB():

print('test')
checkSQL = frappe.db.sql("""SELECT name FROM `tabDelivery Note`""", as_dict=True)
print(checkSQL)
print('test end')

queryDB()

but I am having this output and error after running the debug:

test
Traceback (most recent call last):
File “/home/seanmarkmira/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 72, in getattr
return self.storage[self.ident_func()][name]
KeyError: 139818003855168

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/seanmarkmira/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 309, in _get_current_object
return getattr(self.__local, self.name)
File “/home/seanmarkmira/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 74, in getattr
raise AttributeError(name)
AttributeError: db

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/seanmarkmira/frappe-bench/apps/x_app/x_app/x_app/doctype/expected_return/testDB.py”, line 11, in
queryDB()
File “/home/seanmarkmira/frappe-bench/apps/x_app/x_app/x_app/doctype/expected_return/testDB.py”, line 7, in queryDB
checkSQL = frappe.db.sql(""“SELECT name FROM tabDelivery Note“””, as_dict=True)
File “/home/seanmarkmira/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 348, in getattr
return getattr(self._get_current_object(), name)
File “/home/seanmarkmira/frappe-bench/env/lib/python3.6/site-packages/werkzeug/local.py”, line 311, in _get_current_object
raise RuntimeError(“no object bound to %s” % self.name)
RuntimeError: no object bound to db’

I already followed this setup for VS Code. Already updated the program, pythonpath, and CWD. Still having problems with this. How to fix this problem? Any help would be highly appreciated.

Found a workaround. Closing this one. Used Profiling part documented here

1 Like