Debugging Python File with VSCode and Remote SSH

Hello,

I have a Virtual Machine with bench / frappe installed. I am using VSCode with the Extension “Remote SSH” to connect to the Virtual Machine. There I installed a custom app and now I am trying to debug a python file.

I have followed this guide

and debugging starts.

But:
Within the python file I am debugging I use frappe.get_doc(“MyDoctype”, “thename”) and when trying to run this I get the Exception: “no object bound to db”

Exception has occurred: RuntimeError
no object bound to db
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 38, in get_controller
module_name, custom = frappe.db.get_value(“DocType”, doctype, (“module”, “custom”), cache=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 69, in get_doc
controller = get_controller(doctype)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 762, in get_doc
doc = frappe.model.document.get_doc(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/ice/ice/api.py”, line 64, in sync_calendar
md = frappe.get_doc(“MyDoctype”, “thename”)
File “/home/frappe/frappe-bench/apps/ice/ice/api.py”, line 581, in
message = my_function(data)

I have searched all answers in this forum with no result, can somebody give me a hint?

Hi, will need more details to help you debug this…

Any errors on installation? Or did you make any changes to the site config?

Also try running bench --site <sitename> mariadb and see if you can connect to the db…

Hi,

thank you for the reply. I have made just one change to the site_config.json (“developer_mode” : 1). With bench --site localhost mariadb I can connect to the db.

If I run bench start with the original Procfile everything works well. Where can I check if there were errors on installation? What logs can I provide to you?

Is it because of VSCode Remote SSH maybe?

Hello,

i have tried to set up a remote database setup following this guide:

Unfortunatley it did still return “no object bound to db” . From what I believe it has to do with the frappe framework (e.g. frappe.db) not initializing properly in the VS Code Remote SSH Mode while debugging.

I tried to pin it down within frappe.database.py but the init-method of the database.py file is not being called at all when debugging from VSCode.

Assuming that you followed all the steps mentioned in guide.

  1. Make sure the name of site is same as the one you are entering in browser. It seems that you’ve named it localhost and are probably accessing it using http://localhost:8000/ . If so, this part is correct.
  2. Make sure that the site you want to use for debugging is set as default by issuing the command bench use <your sitename>
  3. Run bench start - This will start Redis, file watcher and other stuff
  4. Hit F5 in vscode to launch werkzeug with vscode debugger attached

Note: Setting up remote database may be irrelevant here.

I’m using this setup over Remote SSH for quite a while without any issues.

Regards

I clearly must be doing something wrong. But I carefully went over all the configurations again.
Maybe I am trying to something that is not possible.

Are you debugging files like:

if name == “main”:
some_function()

I setup a new site named localguest and am trying to access it via localguest:8000

Regards