Using my odoo.sh project (v13.0.2) > EDITOR-Tab , which redirects me to mywebsite.odoo.com/odoo-sh/editor/lab, when i want to debug using import pdb; pdb.set_trace(), it raises a BdbQuit Error :
File "/usr/lib/python3.6/bdb.py", line 113, in
dispatch_exception
if self.quitting: raise BdbQuit
In the past versions : v13.0.1.xxx, i could use pdb.set_trace() to debug my python code. How to solve this issue ?
CodePudding user response:
Using this post How to debug python CLI that takes stdin?, I have managed it this way :
in Odoo.sh>EDITOR (Jupyter Lab): Open a first Terminal and create these two fifos which will be used as stdin/stdout to use pdb :
mkfifo fifo_stdin mkfifo fifo_stdout cat fifo_stdout & cat > fifo_stdin
...which makes appear a prompt cursor. Keep this Terminal Tab opened.
Write these 2 lines at the top of the Python script to be debugged :
import pdb mypdb=pdb.Pdb(stdin=open('fifo_stdin','r'), stdout=open('fifo_stdout','w'))
In this Python script, call set_trace() on your customized mypdb using the 2 fifos
def _get_total_amount(self): total_amount = sum(self._get_base_order_lines(program).mapped('price_total')) mypdb.set_trace() return total_amount
Open a second Terminal to launch your Odoo application :
odoo-bin -u sale_coupon --stop-after-init
...and wait till all modules get loaded
Switch to the first Terminal window (fifo)
In another Webbrowser-tab : Browse on your Odoo App / Website to trigger the function where you put your set_trace()
Go to the first Terminal and input function variables to be observed :
total_amount 1480.0 (Pdb)
Go further in your app process (next breakpoint if any) using "continue" and abort debugging using "quit"
(Pdb) continue (Pdb) quit
Exit pdb using the keyboard combination : Ctrl D
Odoo could remain hanging, which required to comment the pdb-lines in the python script, close Terminal windows and relaunched your Odoo-App :
odoo-bin -u sale_coupon --stop-after-init